home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / footiefox-2.1.2-fx.xpi / chrome / footiefox.jar / content / footiefox / footiefox.js < prev    next >
Text File  |  2008-07-01  |  157KB  |  4,929 lines

  1.  /* ***** BEGIN LICENSE BLOCK *****
  2. EULA
  3.  
  4. Terms of use
  5.  
  6. The FootieFox - Boris Ruf and Jan Schulz-Hofen GbR (ôFootieFoxö) grants you the non-transferable, non-exclusive and revocable right to use the FootieFox Software free of charge, for your personal, non-commercial use only, subject to this licensing agreement. However, you may not use the FootieFox Software in any manner that could overburden, impair or damage the FootieFox Web Service (e.g., you are not allowed to use the FootieFox Software in an automated manner).
  7.  
  8. Intellectual Property
  9.  
  10. After obtaining written consent of FootieFox by e-mail (contact@footiefox.com) you are permitted to offer the FootieFox Software as a whole, without any modifications and free of charge for download on your website other than footiefox.com. You may not lease, rent or sell the FootieFox Software or the information presented to you through the FootieFox Software. Furthermore, you may not sublicense or otherwise transfer any right in the FootieFox Software. You agree not to modify, adapt, translate, decompile, reverse engineer, disassemble or otherwise attempt to derive source code from the FootieFox Software. Distributing or creating derivative works based on the FootieFox Software is expressly not permitted. You also agree to not remove, obscure, or alter FootieFoxÆ and or any third partyÆs copyright notice, trademarks, or other proprietary rights notices presented through or contained in the FootieFox Software.
  11.  
  12. Disclaimer of Warranties
  13.  
  14. The FootieFox Software is provided free of charge and with no warranties whatsoever. FootieFox and any third party who provides its service through the FootieFox Software disclaim any responsibility for any harm resulting from the use of the FootieFox Software and/or any service provided by any third party through the FootieFox Software.
  15.  
  16. THE FOOTIEFOX SOFTWARE IS PROVIDED ôAS ISö WITH ALL FAULTS AND WITH NO WARRANTIES WHATSOEVER. FOOTIEFOX EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES THAT THE PRODUCT IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE AND NON-INFRINGING. FOOTIEFOX AND THIRD PARTIES WHO PROVIDE SERVICE THROUGH THE FOOTIEFOX SOFTWARE DISCLAIM ANY WARRANTIES REGARDING THE SECURITY, RELIABILITY, TIMELINESS, AND PERFORMANCE OF THE FOOTIEFOX SOFTWARE AND/OR THE INFORMATION PRESENTED TO YOU THROUGH THE FOOTIEFOX SOFTWARE.
  17.  
  18. YOU UNDERSTAND AND AGREE THAT YOU BEAR ENTIRE RISK AS TO THE FITNESS, THE QUALITY AND THE PERFORMANCE OF THE PRODUCT AND THAT YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGES TO YOUR COMPUTER SYSTEM OR LOSS OF DATA THAT RESULTS FROM THE DOWNLOAD OR USE OF THE FOOTIEFOX SOFTWARE. IN SOME COUNTRIES THE EXCLUSION OR LIMITATION OF IMPLIED WARRANTIES IS NOT ALLOWED, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
  19.  
  20. Limitation of Liability
  21.  
  22. TO THE EXTENT PERMITTED BY LAW, FOOTIEFOX OR ANY THIRD PARTY WILL NOT BE LIABLE FOR ANY INDIRECT, SPECIAL, INCIDENTAL, CONSEQUENTIAL OR EXEMPLARY DAMAGES ARISING OUT OF OR IN ANY WAY RELATING TO THIS LICENSING AGREEMENT OR THE USE OF OR INABILITY TO USE THE FOOTIEFOX SOFTWARE, INCLUDING WITHOUT LIMITATION DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, LOST PROFITS, LOSS OF DATA, AND COMPUTER FAILURE OR MALFUNCTION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND REGARDLESS OF THE THEORY (E.G. CONTRACT OR TORT) UPON WHICH SUCH CLAIM IS BASED. IN SOME COUNTRIES THE EXCLUSION OR LIMITATION OF LIABILITY FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES IS NOT ALLOWED, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
  23.  
  24. Other Terms
  25.  
  26. The present license agreement will be governed by and construed in accordance with the laws of the Federal Republic of Germany and shall not be governed by the United Nations Convention on the International Sale of Goods. The courts of Berlin shall have exclusive jurisdiction.
  27.  
  28. If any part of this license agreement is held invalid or unenforceable, that part will be construed to reflect the partiesÆ original intent, and the remaining portions will remain in full force and effect.
  29.  
  30. * ***** END LICENSE BLOCK ***** */
  31.  
  32.  
  33.  
  34.  
  35.  
  36. var iFootieFox = null;
  37. var windowfocused = true;
  38. var goalAlertHeight = 0;
  39. var sliders = new Array();
  40. var leagueBaseRefreshed = 0;
  41. var leagueUpdateRefreshed = 0;
  42. var failedLeagues = 0;
  43. var FootieFoxSliderAction = false;
  44.  
  45. //debug switch
  46. var footiefox_d = 0;
  47.  
  48. function ffLoad() {
  49.    
  50.     whereIsFootieFox();    
  51.  
  52.     iFootieFox = new FootieFox();
  53.     
  54.     
  55.     
  56.     iFootieFox.init();
  57.     
  58.     //var oPrefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranchInternal);
  59.     var oDefPref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getDefaultBranch("general.useragent.");
  60.     
  61. }
  62.  
  63.  
  64. function ffUnload() {
  65.  
  66.     //unregister observers
  67.     iFootieFox.myObservers.unregister();
  68.  
  69.     iFootieFox.ffTimer.cancel();
  70.     iFootieFox.ffRotationTimer.cancel();
  71.  
  72.     iFootieFox = null;
  73. }
  74.  
  75. function FootieFox () {
  76.  
  77.     return this;
  78. }
  79.  
  80.  
  81. FootieFox.prototype =
  82. {
  83.  
  84.     prefNode: null,
  85.     dictionary: null,
  86.     firstExtension: false,
  87.     whatsOnCalled: true,
  88.     myLeagues: null,
  89.     myTeams: null,
  90.     myScoreboard: new Array(),
  91.     activeLeagues: null,
  92.     leagueTimestamps: null,
  93.  
  94.     redirectURL: "http://redirect.footiefox.com/",
  95.     first_apiURL: "http://api2.footiefox.com/",
  96.     mediaURL: "http://media.footiefox.com/",
  97.  
  98.     searchEngineURL: "http://en.footiefox.com/files/footiefox.xml",
  99.     imagesSubdirectory: "",
  100.     cacheFolder: "footiefoxCache20",
  101.     rotation: false,
  102.     selectedMatch: null,
  103.     rotationTimer: null,
  104.     soundPlayer: null,
  105.     tmpDir: null,
  106.     updateInterval: 16000,
  107.     messageTimer: null,
  108.     iframeTimer: new Array(),
  109.     lastMessage: 0,
  110.     messages: null,
  111.     
  112.     banner: null,
  113.     scoreAds: null,
  114.     scoreAd: null,
  115.     availableHosts: new Array(),
  116.     ETchecking: false,
  117.     menu_visible: false,
  118.     failedConnections: 0,
  119.     lastUpdate:0,
  120.  
  121.  
  122.  
  123.     init: function() {
  124.     
  125.         //openDialog("chrome://footiefox/content/wizard.xul", "wizard", "chrome,dialog");
  126.  
  127.         
  128.         //initialize preferences
  129.         var gDBTPrefService = Components.classes["@mozilla.org/preferences-service;1"]
  130.                    .getService(Components.interfaces.nsIPrefService);
  131.  
  132.         this.prefNode = gDBTPrefService.getBranch("extensions.footiefox.");
  133.  
  134.  
  135.           //if preferences not available set default preferences
  136.         if ( !this.prefNode.prefHasUserValue("alertmode") )
  137.             this.prefNode.setCharPref("alertmode", "league");
  138.  
  139.         if ( !this.prefNode.prefHasUserValue("leaguestofollow") )
  140.             this.prefNode.setCharPref("leaguestofollow", "");
  141.  
  142.         if ( !this.prefNode.prefHasUserValue("teamstofollow") )
  143.             this.prefNode.setCharPref("teamstofollow", "");
  144.  
  145.  
  146.         if ( !this.prefNode.prefHasUserValue("showslider") )
  147.             this.prefNode.setBoolPref("showslider", true);
  148.  
  149.         if ( !this.prefNode.prefHasUserValue("alertmode") )
  150.             this.prefNode.setCharPref("alertmode", "league");
  151.  
  152.         if ( !this.prefNode.prefHasUserValue("playalarm") )
  153.         this.prefNode.setBoolPref("playalarm", true);
  154.  
  155.         if ( !this.prefNode.prefHasUserValue("alarmtype") )
  156.         this.prefNode.setCharPref("alarmtype", "standard");
  157.  
  158.         if ( !this.prefNode.prefHasUserValue("alarmfile") )
  159.             this.prefNode.setCharPref("alarmfile", "");
  160.  
  161.         if ( !this.prefNode.prefHasUserValue("discretemode") )
  162.             this.prefNode.setBoolPref("discretemode", false);
  163.  
  164.         if ( !this.prefNode.prefHasUserValue("rotationintervall") )
  165.             this.prefNode.setIntPref("rotationintervall", 10);
  166.  
  167.         if ( !this.prefNode.prefHasUserValue("sliderdisplayduration") || !this.prefNode.prefHasUserValue("newdisplayduration")) {
  168.                 this.prefNode.setIntPref("sliderdisplayduration", 10);
  169.                 this.prefNode.setBoolPref("newdisplayduration", true);
  170.         }
  171.  
  172.         if ( !this.prefNode.prefHasUserValue("rotationscope") )
  173.             this.prefNode.setCharPref("rotationscope", "all");
  174.             
  175.         if ( !this.prefNode.prefHasUserValue("ET") )
  176.             this.prefNode.setCharPref("ET", "0");
  177.  
  178.         if ( !this.prefNode.prefHasUserValue("menuitemsshowscores") )
  179.             this.prefNode.setBoolPref("menuitemsshowscores", true);
  180.  
  181.         if ( !this.prefNode.prefHasUserValue("menuitemsshowdate") )
  182.             this.prefNode.setBoolPref("menuitemsshowdate", true);
  183.  
  184.         if ( !this.prefNode.prefHasUserValue("menulayout") )
  185.             this.prefNode.setCharPref("menulayout", "both");
  186.  
  187.         if ( !this.prefNode.prefHasUserValue("teamslisttimestamp") )
  188.             this.prefNode.setCharPref("teamslisttimestamp", "");
  189.  
  190.         if ( !this.prefNode.prefHasUserValue("leagueslisttimestamp") )
  191.             this.prefNode.setCharPref("leagueslisttimestamp", "");
  192.             
  193.         if ( !this.prefNode.prefHasUserValue("color.scheduled") )
  194.             this.prefNode.setCharPref("color.scheduled", "#868686");
  195.             
  196.         if ( !this.prefNode.prefHasUserValue("color.active") )
  197.             this.prefNode.setCharPref("color.active", "#CC0100");
  198.             
  199.         if ( !this.prefNode.prefHasUserValue("color.finished") )
  200.             this.prefNode.setCharPref("color.finished", "#868686");
  201.         
  202.         if ( !this.prefNode.prefHasUserValue("iframes") )
  203.             this.prefNode.setCharPref("iframes", "");
  204.         
  205.         if ( !this.prefNode.prefHasUserValue("host") )
  206.             this.prefNode.setCharPref("host", "");
  207.         
  208.         // set favorite server as api host if available
  209.         if ( this.prefNode.getCharPref("host") != "" ) {
  210.             this.apiURL = this.prefNode.getCharPref("host");
  211.         } else {
  212.             this.apiURL = this.first_apiURL;
  213.         }
  214.                 
  215.         if ( !this.prefNode.prefHasUserValue("locale") ) {
  216.             
  217.             var locale = "en-US";
  218.             try {
  219.                 
  220.                 var cls = '@mozilla.org/chrome/chrome-registry;1';
  221.                 var service = Components.interfaces.nsIXULChromeRegistry;
  222.                 var locale = Components.classes[cls].getService(service).getSelectedLocale('footiefox');
  223.                 
  224.             } catch (e) {
  225.                 
  226.                 footiefox_d_error("Failed to detect selected locale for FootieFox: "+e);
  227.                 
  228.             
  229.             }
  230.             
  231.             this.prefNode.setCharPref("locale", locale);
  232.             
  233.         }
  234.         
  235.         if ( !this.prefNode.prefHasUserValue("partner") )
  236.             this.prefNode.setCharPref("partner", "1");
  237.         
  238.         this.partners = document.getElementById("partners-data-bundle");
  239.         
  240.         var partner = null;
  241.         
  242.             
  243.              
  244.         try {
  245.             // no locale partner
  246.             var partnerNum = this.prefNode.getCharPref("partner");
  247.             partner = this.partners.getString(partnerNum).split(":")[1];
  248.          
  249.         } catch (e) {
  250.             this.prefNode.setCharPref("partner", "1");
  251.             partner = 1;
  252.         
  253.         }
  254.         
  255.         
  256.         //if ( !this.prefNode.prefHasUserValue("partner.toolbarbutton") ) 
  257.         //    this.prefNode.setBoolPref("partner.toolbarbutton", true);
  258.         
  259.         if ( !this.prefNode.prefHasUserValue("partner.toolbarbuttons") ) {
  260.             var buttons = "";
  261.             if ( this.prefNode.prefHasUserValue("partner.toolbarbutton") ) {
  262.                 if ( this.prefNode.getBoolPref("partner.toolbarbutton") )
  263.                     buttons = "1";
  264.             }
  265.             this.prefNode.setCharPref("partner.toolbarbuttons", buttons);
  266.         }
  267.         
  268.         //add partner toolbar button
  269.         this.addToolbarButtons();
  270.         
  271.         var statusbar = document.getElementById("statusbarpanel_partner_logo");
  272.         statusbar.setAttribute("src", "chrome://footiefox/skin/"+partnerNum+"/statusbar.png");
  273.    
  274.             
  275.         if ( !this.prefNode.prefHasUserValue("partner.statusbarlabel") ) 
  276.             this.prefNode.setBoolPref("partner.statusbarlabel", true);
  277.         
  278.        
  279.         if (!this.prefNode.getBoolPref("partner.statusbarlabel")) {
  280.             var label = document.getElementById("deck_partner_logo");
  281.             label.setAttribute("hidden", true);
  282.         
  283.         }
  284.         
  285.         
  286.         //check for network.http.use-cache
  287.         try {
  288.             var general = gDBTPrefService.getBranch("network.http.");
  289.             if(!general.getBoolPref("use-cache")) {
  290.                 
  291.                 var question = "FootieFox requires HTTP caching (preference 'network.http.use-cache'), otherwise the Add-on has to be disabled. May we enable it for you?"; 
  292.                 var enable = confirm(question);
  293.                 
  294.                 if (enable) {
  295.                     general.setBoolPref("use-cache", true);
  296.                     
  297.                 } else {
  298.                     
  299.                     var extensionManager = Components.classes["@mozilla.org/extensions/manager;1"].
  300.                         getService(Components.interfaces.nsIExtensionManager);
  301.                     var extensionId = "{9fb7d178-155a-4318-9173-1a8eaaea7fe4}";
  302.                     extensionManager.disableItem(extensionId);
  303.                     
  304.                     window.setTimeout(this.restartFirefox(), 500);
  305.                     
  306.                 }
  307.                 
  308.                 
  309.             }
  310.         } catch (e) {
  311.         
  312.             footiefox_d_error("check for network.http.use-cache failed: " + e);
  313.         }
  314.  
  315.  
  316.         
  317.         
  318.         this.myObservers = new myObservers();
  319.  
  320.         this.ffTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  321.         this.ffRotationTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  322.  
  323.  
  324.         if ( (!this.prefNode.prefHasUserValue("tempdir")) || this.prefNode.getCharPref("tempdir")=="" ) {
  325.             
  326.         
  327.             //determine directory for image cache
  328.             var oProps = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
  329.             this.tmpDir = (oProps.get("TmpD", Components.interfaces.nsIFile)).path;
  330.                 
  331.             
  332.  
  333.             if (this.tmpDir != "") {
  334.             //get slash direction
  335.                 var sSlash = (this.tmpDir.indexOf("\\") > -1) ? "\\" : "/";
  336.                 this.tmpDir += sSlash + this.cacheFolder + sSlash;
  337.             }
  338.  
  339.             this.prefNode.setCharPref("tempdir", this.tmpDir);
  340.         } else
  341.             this.tmpDir = this.prefNode.getCharPref("tempdir");
  342.  
  343.  
  344.         this.checkFirstExtension();
  345.  
  346.         var leaguesDataBundleUpdated = document.getElementById("leagues-data-bundle-updated");
  347.  
  348.         if (this.inCache("leagues.dat")) {
  349.         //check if local leagues.dat valid
  350.             try {
  351.  
  352.                 leaguesDataBundleUpdated.setAttribute("src", "file://" + this.tmpDir + "leagues.dat");
  353.                 var leaguesDataString = leaguesDataBundleUpdated.getString(1);
  354.  
  355.  
  356.  
  357.                 //leagues.dat corrupt
  358.                 } catch (e) {
  359.  
  360.                     footiefox_d_error("leagues.dat corrupt");
  361.                     leaguesDataBundleUpdated.removeAttribute("src");
  362.                     //reset leagueslisttimestamp so leagues.dat is being reloaded
  363.                     this.prefNode.setCharPref("leagueslisttimestamp", "");
  364.  
  365.                    }
  366.             }
  367.  
  368.                 //check if menuheader in cache and set url accordingly
  369.             if (this.inCache("contextmenuheader.png"))
  370.                 var headerurl = "file://" + this.tmpDir + "contextmenuheader.png";
  371.             else
  372.                 var headerurl = this.mediaURL + this.imagesSubdirectory + "contextmenuheader.png";
  373.  
  374.                 var menuHeader = document.getElementById("menu_header");
  375.                 menuHeader.setAttribute("src", headerurl);
  376.  
  377.  
  378.  
  379.         var teamsDataBundleUpdated = document.getElementById("teams-data-bundle-updated");
  380.  
  381.         if (this.inCache("teams.dat")) {
  382.         //check if local teams.dat valid
  383.             try {
  384.  
  385.                 teamsDataBundleUpdated.setAttribute("src", "file://" + this.tmpDir + "teams.dat");
  386.                 var teamsDataString = teamsDataBundleUpdated.getString(11);
  387.  
  388.  
  389.  
  390.             //teams.dat corrupt
  391.             } catch (e) {
  392.                 
  393.                 footiefox_d_error("teams.dat corrupt");
  394.                 teamsDataBundleUpdated.removeAttribute("src");
  395.                 //reset teamslisttimestamp so teams.dat is being reloaded
  396.                 this.prefNode.setCharPref("teamslisttimestamp", "");
  397.  
  398.             }
  399.         }
  400.         
  401.         this.checkET();
  402.         
  403.         this.checkVersionUpdate();
  404.  
  405.         this.applyLanguagePackage(this.prefNode.getCharPref("locale"));
  406.         this.applyPartnerOverlay();
  407.  
  408.  
  409.         this.soundPlayer = Components.classes["@mozilla.org/sound;1"].createInstance();
  410.  
  411.  
  412.  
  413.         this.rotationTimer = {
  414.  
  415.             notify: function() {
  416.  
  417.                 var rotationscope = iFootieFox.prefNode.getCharPref("rotationscope");
  418.  
  419.                 if ( rotationscope == "all" ) {
  420.                     var num = iFootieFox.getNumberOfActiveMatches();
  421.                     
  422.                     if ( num == 0 )
  423.                         iFootieFox.displayMatch ( iFootieFox.getNextMatch() );
  424.                     else
  425.                         iFootieFox.displayMatch ( iFootieFox.getNextActiveMatch() );
  426.                         
  427.                 } else {
  428.                     var num = iFootieFox.getNumberOfActiveMatchesInLeague();
  429.                     if ( num == 0 )
  430.                         iFootieFox.displayMatch ( iFootieFox.getNextMatchInLeague() );
  431.                     else
  432.                         iFootieFox.displayMatch ( iFootieFox.getNextActiveMatchInLeague() );
  433.                 }
  434.  
  435.             }
  436.         };
  437.  
  438.         if ( this.prefNode.prefHasUserValue("rotation") ) {
  439.  
  440.             this.rotation = this.prefNode.getBoolPref("rotation");
  441.  
  442.             if (this.rotation) {
  443.  
  444.                 var rotationbox = document.getElementById("ff_popupmenu_rotate");
  445.                 rotationbox.setAttribute("checked", true);
  446.                 this.rotation = false;
  447.                 this.toggleRotate();
  448.             }
  449.         }
  450.  
  451.         
  452.         this.updateLeagues = {
  453.             
  454.             notify: function() {
  455.                 
  456.                 iFootieFox.checkFirstExtension();
  457.  
  458.                 if ( !iFootieFox.firstExtension )
  459.                     return;
  460.                 
  461.                 var now = new Date(); 
  462.                 
  463.                 if (iFootieFox.lastUpdate != 0 && (parseInt(now.getTime()) - parseInt(iFootieFox.lastUpdate)) > 600000) {
  464.                     
  465.                     iFootieFox.lastUpdate = now.getTime();
  466.                     
  467.                     footiefox_d_error("Browser has been hibernating ... refresh data");
  468.                     setTimeout("iFootieFox.callWhatsOn(false)", 3000);
  469.                     return;
  470.                 }
  471.  
  472.                 var leagues = iFootieFox.myScoreboard;
  473.                 leagueUpdateRefreshed = 0;
  474.                 for ( var i=0; i<leagues.length; i++ ) {
  475.  
  476.                     var league = leagues[i];
  477.                     
  478.                     iFootieFox.requestLeagueUpdate( league.leagueID );
  479.  
  480.                 }
  481.                 
  482.                 now = new Date();
  483.                 
  484.                 iFootieFox.lastUpdate = now.getTime();
  485.             }
  486.            
  487.         };
  488.         
  489.         //check if whatson data outdated (hibernating)
  490.         this.regularWhatsOnCall = {
  491.  
  492.             notify: function() {
  493.                 
  494.                 if ( iFootieFox.prefNode.prefHasUserValue("logintimestamp") ) {
  495.  
  496.                     var lastLogTimestamp = parseInt( iFootieFox.prefNode.getCharPref("logintimestamp"));
  497.  
  498.                     var lastLog = new Date ( lastLogTimestamp );
  499.  
  500.                     var currentTime = new Date();
  501.  
  502.                     //new GMT day
  503.                     if ( lastLog.getUTCDate() != currentTime.getUTCDate() ) {
  504.                         
  505.                         iFootieFox.callWhatsOn(false);
  506.                     }
  507.                     
  508.                 } else {
  509.                     iFootieFox.callWhatsOn(false);
  510.                 }
  511.                 
  512.             }
  513.         };
  514.     
  515.         this.whatsonTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  516.         this.whatsonTimer.initWithCallback(this.regularWhatsOnCall, 1000*60*30, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
  517.  
  518.         
  519.         this.login();
  520.  
  521.         window.addEventListener("focus", this.infocus, true);
  522.         window.addEventListener("blur", this.blurred, true);
  523.  
  524.  
  525.     },
  526.     
  527.     restartFirefox: function() {
  528.   
  529.       
  530.       var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"].
  531.                          getService(Components.interfaces.nsIAppStartup);
  532.       appStartup.quit(Components.interfaces.nsIAppStartup.eForceQuit | Components.interfaces.nsIAppStartup.eRestart);
  533.    },
  534.     
  535.     
  536.     applyLanguagePackage: function(locale) {
  537.     
  538.     
  539.     
  540.         var stringbundleDictionary = document.getElementById("stringbundle_dictionary");
  541.         //stringbundleDictionary.removeAttribute("src");
  542.         stringbundleDictionary.setAttribute("src", "chrome://footiefox/locale/"+locale+"/footiefox/footiefox.properties");
  543.         this.dictionary = document.getElementById("stringbundle_dictionary");
  544.         
  545.          
  546.         var countriesDataBundle = document.getElementById("countries-data-bundle");
  547.         countriesDataBundle.setAttribute("src", "chrome://footiefox/locale/"+locale+"/footiefox/countries.dat");
  548.         
  549.         
  550.         
  551.         //document.loadOverlay("chrome://footiefox/locale/en-US/footiefox/footiefox.dtd", null);
  552.  
  553.         this.translate("ff_popupmenu_configurepartner"); 
  554.         this.translate("ff_popupmenu_matchreport1","ff.popupmenu.matchreport");
  555.         this.translate("ff_popupmenu_matchreport2","ff.popupmenu.matchreport");
  556.         this.translate("icon1menupopup_teamlocalization", "ff.popupmenu.localizeteam");
  557.         this.translate("icon2menupopup_teamlocalization", "ff.popupmenu.localizeteam");
  558.         this.translate("ff_popupmenu_rotate");        
  559.         this.translate("ff_popupmenu_options");
  560.         this.translate("ff_popupmenu_about");        
  561.         this.translate("ff_notice_nomatches", null, "value");
  562.         this.translate("ff_notice_noconnection");        
  563.         this.translate("ff_notice_noleagues");
  564.         this.translate("ff_alerts_goal", null, "value");
  565.         
  566.     
  567.     },
  568.         
  569.     translate: function(element_id, dictionary_id, attribute) {
  570.     
  571.         if (attribute == null){
  572.             attribute = "label";
  573.         }
  574.         
  575.         if (dictionary_id == null){
  576.             dictionary_id = element_id.replace(/_/g,".");
  577.         }
  578.     
  579.         try {
  580.             var element = document.getElementById(element_id);
  581.             element.setAttribute(attribute, this.dictionary.getString(dictionary_id));
  582.         } catch (e) {
  583.  
  584.             //d("Failed to translate " + element_id);
  585.         }
  586.     },
  587.     
  588.     translateById: function (dictionary_id, original) {
  589.         
  590.         try {
  591.             translation = this.dictionary.getString(dictionary_id);
  592.             return translation;
  593.         } catch (e) {
  594.         
  595.         
  596.             return original;
  597.             
  598.         }
  599.     
  600.     },
  601.     
  602.     addSearchEngine: function() {
  603.         
  604.             try {
  605.                 
  606.                 var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
  607.                         .getService(Components.interfaces.nsIXULAppInfo);
  608.                 var versionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"]
  609.                                .getService(Components.interfaces.nsIVersionComparator);
  610.                 
  611.                 //check if Firefox version is >= 2.0
  612.                 if(versionChecker.compare(appInfo.version, "2.0") >= 0) {
  613.                     //add search engine
  614.                     window.external.AddSearchProvider(this.searchEngineURL);
  615.                 }
  616.                 
  617.             } catch (e) {
  618.                 footiefox_d_error(e);
  619.                 return;
  620.             }
  621.         
  622.         },
  623.         
  624.     addToolbarButton: function(id) {
  625.         
  626.         
  627.         try {
  628.  
  629.             if(document.getElementById("footiefox-partner-button-"+id)!=null)
  630.                 return;
  631.             
  632.         
  633.             var button = document.createElement("toolbarbutton");
  634.             button.setAttribute("id", "footiefox-partner-button-"+id);
  635.             
  636.             button.setAttribute("context", "menupopup_partnermenupopup");
  637.             button.setAttribute("collapsed", "false");
  638.             button.setAttribute("hidden", "false");
  639.             button.setAttribute("disabled", "false");
  640.             button.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional footiefox-partner-button");
  641.             button.setAttribute("oncommand", "iFootieFox.partnerBannerClicked(null, 12, " + id +")");
  642.             
  643.             button.setAttribute("style", "list-style-image: url(\"chrome://footiefox/skin/"+id+"/button.png\");");
  644.  
  645.             var navbar = document.getElementById("nav-bar");
  646.             navbar.insertBefore(button, document.getElementById("urlbar-container"));
  647.             
  648.         } catch(ex) {
  649.         
  650.             footiefox_d_error("Failed to add FootieFox partner button "+id+" to toolbar." + ex);
  651.         }
  652.         
  653.         
  654.     },
  655.     
  656.     removeToolbarButtons: function() {
  657.     
  658.         var partnersEnum = this.partners.strings;
  659.         var index = -1;
  660.         var navbar = document.getElementById("nav-bar");
  661.         
  662.         while (partnersEnum.hasMoreElements()) {
  663.             
  664.             var element = partnersEnum.getNext();
  665.             var key = element.QueryInterface(Components.interfaces.nsIPropertyElement).key;
  666.             var button = document.getElementById("footiefox-partner-button-" + key);
  667.             try {
  668.                 if (button!= null)
  669.                     navbar.removeChild(button);
  670.             } catch (e) {
  671.                 footiefox_d_error(e);
  672.             }
  673.             
  674.         }
  675.     },
  676.     
  677.     addToolbarButtons: function() {
  678.     
  679.         this.removeToolbarButtons();
  680.         
  681.         var buttonsString = this.prefNode.getCharPref("partner.toolbarbuttons");
  682.         var buttonsArray = buttonsString.split(":");
  683.         
  684.         for (var i=0;i<buttonsArray.length;i++) {
  685.             var partnerNum = buttonsArray[i];
  686.             if(isNaN(parseInt(partnerNum)))
  687.                 continue;
  688.             this.addToolbarButton(buttonsArray[i]);
  689.         }
  690.         
  691.     },
  692.     
  693.         
  694.     checkVersionUpdate: function() {
  695.             
  696.             var field = "version";
  697.             var extensionId = "{9fb7d178-155a-4318-9173-1a8eaaea7fe4}";
  698.  
  699.             var rdfs = Components.classes["@mozilla.org/rdf/rdf-service;1"]
  700.                                         .getService(Components.interfaces.nsIRDFService);
  701.             var extensionDS = Components.classes["@mozilla.org/extensions/manager;1"]
  702.                                     .getService(Components.interfaces.nsIExtensionManager).datasource;
  703.             var extension = rdfs.GetResource("urn:mozilla:item:" + extensionId);
  704.             var fieldArc = rdfs.GetResource(
  705.                      "http://www.mozilla.org/2004/em-rdf#" + field);
  706.             var valueLiteral = extensionDS.GetTarget(extension, fieldArc, true);
  707.  
  708.             // value contains the string
  709.             var version = valueLiteral.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  710.             
  711.             var oldversion = null;
  712.             try {
  713.                 oldversion = this.prefNode.getCharPref("version");
  714.             } catch (e) {}
  715.             
  716.             var eula = null;
  717.             if (this.prefNode.prefHasUserValue("eula")) {
  718.                 eula = this.prefNode.getCharPref("eula");
  719.             }
  720.             
  721.             
  722.  
  723.             //updated!
  724.             if (!this.prefNode.prefHasUserValue("version") || oldversion != version || eula!="accepted") {
  725.                 
  726.                 this.prefNode.setCharPref("version", version);
  727.                                 
  728.                 var language = "en";
  729.                 
  730.                 var gDBTPrefService = Components.classes["@mozilla.org/preferences-service;1"]
  731.                    .getService(Components.interfaces.nsIPrefService);
  732.  
  733.                 try {
  734.                     var general = gDBTPrefService.getBranch("general.useragent.");
  735.                     var loc = general.getCharPref("locale");
  736.                     
  737.                     if (loc =="de-DE" || loc=="de")
  738.                         language = "de";
  739.                 } catch(e) {};
  740.                 
  741.                 //open website on version history
  742.                 var browser = document.getElementById("content");
  743.                 var tab = browser.addTab("http://"+language+".footiefox.com/pages/update/"+version);
  744.                 browser.selectedTab = tab;
  745.                 
  746.                 
  747.                 
  748.                 //update from 1.x to 2.x
  749.                 if ( oldversion == null || (oldversion.split(".")[0]=="1" && version.split(".")[0]=="2" || eula!="accepted" )) {
  750.                     
  751.                     //remove old IDs
  752.                     iFootieFox.prefNode.setCharPref("leaguestofollow", "");
  753.                     iFootieFox.prefNode.setCharPref("teamstofollow", "");
  754.                     
  755.                     //openDialog('chrome://footiefox/content/wizard.xul', 'wizard', 'chrome,dialog,modal,centerscreen');
  756.                     wiz = window.openDialog('chrome://footiefox/content/wizard.xul', 'wizard', 'chrome,dialog,centerscreen');
  757.                     window.setTimeout(iFootieFox.focusWizard, 1000);
  758.                     
  759.                 } else {
  760.                 
  761.                     if (!this.isSearchEngineInstalled())
  762.                         this.addSearchEngine();
  763.                 
  764.                 }
  765.                 
  766.             }
  767.  
  768.         },
  769.         
  770.         focusWizard: function() {
  771.             wiz.focus();
  772.         },
  773.         
  774.         isSearchEngineInstalled: function () {
  775.             
  776.             var searchService = Cc["@mozilla.org/browser/search-service;1"].getService(Ci.nsIBrowserSearchService);
  777.             var engineName = searchService.currentEngine.name;
  778.             
  779.             if (searchService.getEngineByName("FootieFox") == null) 
  780.                 return false;
  781.             else
  782.                 return true;
  783.         
  784.         },
  785.  
  786.  
  787.         showSlider: function() {
  788.  
  789.             var goalwin = document.getElementById("ff_alert");
  790.  
  791.             goalwin.setAttribute("hidden", "false");
  792.             
  793.             var ad = iFootieFox.scoreAd;
  794.  
  795.             var h = 108;
  796.             var w = 200;
  797.  
  798.             //adjust size for ad
  799.             if (ad != null) {
  800.  
  801.                     h += ad.height;
  802.                     w = ad.width;
  803.             }
  804.  
  805.             
  806.             var style = "height:" + goalAlertHeight +"px;width:"+w+"px;z-Index:300;overflow-x:auto;overflow-y:hidden;";
  807.             
  808.             goalwin.setAttribute("style", style);
  809.  
  810.             goalAlertHeight = goalAlertHeight + 1;
  811.            
  812.  
  813.             if (goalAlertHeight < h )
  814.                 window.setTimeout(iFootieFox.showSlider,20);
  815.             else {
  816.                 goalAlertHeight = 0;
  817.                 var displayduration = iFootieFox.prefNode.getIntPref("sliderdisplayduration");
  818.                 window.setTimeout(iFootieFox.hideSlider,displayduration*1000);
  819.             }
  820.  
  821.         },
  822.  
  823.         hideSlider: function() {
  824.  
  825.             var goalwin = document.getElementById("ff_alert");
  826.  
  827.             goalwin.setAttribute("hidden", "false");
  828.  
  829.             var ad = iFootieFox.scoreAd;
  830.  
  831.             var h = 108;
  832.             var w = 200;
  833.  
  834.         //adjust size for ad
  835.         if (ad != null) {
  836.  
  837.                     h += ad.height;
  838.                     w = ad.width;
  839.             }
  840.  
  841.             var style = "height:"+parseInt(h-goalAlertHeight)+"px;width:" + w + "px;overflow-x:auto;overflow-y:hidden;";
  842.  
  843.                 goalwin.setAttribute("style", style);
  844.  
  845.  
  846.                 goalAlertHeight = goalAlertHeight + 1;
  847.  
  848.                 if (goalAlertHeight < h )
  849.                     window.setTimeout(iFootieFox.hideSlider,20);
  850.                 else {
  851.                     footiefox_d_message("finally hidden");
  852.                     goalAlertHeight = 0;
  853.                     goalwin.setAttribute("hidden", "true");
  854.                     FootieFoxSliderAction = false;
  855.                     iFootieFox.displayGoalAlert();
  856.                 }
  857.  
  858.  
  859.         },
  860.  
  861.     infocus: function(event) {
  862.  
  863.         windowfocused = true;
  864.     },
  865.  
  866.     blurred: function(event) {
  867.         
  868.         windowfocused = false;
  869.     },
  870.  
  871.     displayGoalAlert: function() {
  872.  
  873.         footiefox_di_message("displayGoalAlert");
  874.  
  875.         
  876.         if ( sliders.length == 0 || sliders == null || FootieFoxSliderAction == true )  {
  877.             footiefox_d_message("FootieFoxSliderAction:  " + FootieFoxSliderAction);
  878.             return;
  879.         }
  880.             
  881.         FootieFoxSliderAction = true;
  882.         
  883.         var matchDiff = sliders.shift();
  884.  
  885.         var matchid = matchDiff.matchId;
  886.  
  887.         var scoringMatch = this.getMatch( matchid );
  888.         
  889.         var teamid = matchDiff.teamId;
  890.  
  891.         var teamtitle = "";
  892.  
  893.         if ( scoringMatch.team1Id == teamid )
  894.             teamtitle = scoringMatch.team1Title;
  895.  
  896.         if ( scoringMatch.team2Id == teamid )
  897.             teamtitle = scoringMatch.team2Title;
  898.  
  899.  
  900.         this.checkFirstExtension();
  901.  
  902.         if ( this.firstExtension ) {
  903.  
  904.             var observerService = Components.classes["@mozilla.org/observer-service;1"]
  905.                 .getService(Components.interfaces.nsIObserverService);
  906.  
  907.  
  908.             var maximizedlist = observerService.enumerateObservers("footiefoxWindowMaximized");
  909.  
  910.             //remove old "maximized" observers
  911.             while ( maximizedlist.hasMoreElements() ) {
  912.                 var observer = maximizedlist.getNext();
  913.  
  914.                 observerService.removeObserver(observer, "footiefoxWindowMaximized");
  915.             }
  916.  
  917.             //all windows make selftest on maximized status
  918.             Components.classes["@mozilla.org/observer-service;1"]
  919.                 .getService(Components.interfaces.nsIObserverService)
  920.                 .notifyObservers(null, "footiefoxMaximized", "");
  921.  
  922.             maximizedlist = observerService.enumerateObservers("footiefoxWindowMaximized");
  923.  
  924.  
  925.  
  926.             if ( maximizedlist.hasMoreElements() ) {
  927.             
  928.             //new sliders
  929.  
  930.             Components.classes["@mozilla.org/observer-service;1"]
  931.                 .getService(Components.interfaces.nsIObserverService)
  932.                 .notifyObservers(null, "footiefoxGoalAlert", teamid + ";" + teamtitle + ";" + matchid + ";" + scoringMatch.team1Score + ";" + scoringMatch.team2Score + ";" + scoringMatch.phase);
  933.  
  934.             } else {
  935.                 //old sliders
  936.                 this.goalAlert(teamid, teamtitle);
  937.             }
  938.  
  939.         }
  940.  
  941.     },
  942.  
  943.     determineAppropriateAd: function (parameters) {
  944.  
  945.         var teamid = parameters.split(";")[0];
  946.         var teamtitle = parameters.split(";")[1];
  947.         var matchid = parameters.split(";")[2];
  948.  
  949.         
  950.         var match = this.getMatch(matchid);
  951.  
  952.         var league = this.getLeagueByMatch( match );
  953.         
  954.         var leagueId = league.leagueID;
  955.         
  956.         var country = this.getCountryByLeague( leagueId );
  957.  
  958.         var gDBTPrefService = Components.classes["@mozilla.org/preferences-service;1"]
  959.             .getService(Components.interfaces.nsIPrefService);
  960.  
  961.         var locale = this.prefNode.getCharPref("locale");
  962.  
  963.         //find appropriate ad here
  964.         var listOfAds = new Array();
  965.  
  966.  
  967.         //ads for scoring team have highest priority
  968.         for ( var i=0; i<this.scoreAds.length; i++ ) {
  969.  
  970.             var currentAd = this.scoreAds[i];
  971.             if ( (currentAd.team_id == teamid) && (currentAd.locale == locale || currentAd.locale == "xx-XX") ) {
  972.                 
  973.                 listOfAds.push(currentAd);
  974.                 continue;
  975.             }
  976.         }
  977.  
  978.         
  979.         //league-speficic ads come second
  980.         if (listOfAds.length == 0) {
  981.  
  982.             for ( var i=0; i<this.scoreAds.length; i++ ) {
  983.  
  984.                 var currentAd = this.scoreAds[i];
  985.  
  986.                 if ( (currentAd.league_id == leagueId) && (currentAd.locale == locale || currentAd.locale == "xx-XX") ) {
  987.                     
  988.                     listOfAds.push(currentAd);
  989.                     continue;
  990.                 }
  991.             }
  992.         }
  993.  
  994.         //country related ads
  995.         if (listOfAds.length == 0) {
  996.  
  997.             for ( var i=0; i<this.scoreAds.length; i++ ) {
  998.  
  999.                 var currentAd = this.scoreAds[i];
  1000.                 if ( (currentAd.country_id == country) && (currentAd.locale == locale || currentAd.locale == "xx-XX") ) {
  1001.                     
  1002.                     listOfAds.push(currentAd);
  1003.                     continue;
  1004.                 }
  1005.             }
  1006.         }
  1007.  
  1008.  
  1009.         //ads for language target group
  1010.         /*if (listOfAds.length == 0) {
  1011.  
  1012.             for ( var i=0; i<this.scoreAds.length; i++ ) {
  1013.  
  1014.                 var currentAd = this.scoreAds[i];
  1015.  
  1016.                 if ( currentAd.locale == locale || currentAd.locale == "xx-XX" ) {
  1017.                     alert("leagueid: "+currentAd.locale +"=="+ locale  );
  1018.                     listOfAds.push(currentAd);
  1019.                     continue;
  1020.                 }
  1021.             }
  1022.         }*/
  1023.  
  1024.         //at least one appropriate ad found
  1025.  
  1026.         var finalAds = new Array();
  1027.         if ( listOfAds.length > 0 ) {
  1028.  
  1029.             var prio = -1;
  1030.  
  1031.             for ( var i=0; i<listOfAds.length; i++ ) {
  1032.  
  1033.                 var currentAd = listOfAds[i];
  1034.                 if (currentAd.priority == prio) {
  1035.                     finalAds.push(currentAd);
  1036.                 }
  1037.  
  1038.                 if (currentAd.priority > prio) {
  1039.                     prio = currentAd.priority;
  1040.  
  1041.                     finalAds = new Array();
  1042.                     finalAds.push(currentAd);
  1043.                 }
  1044.             }
  1045.  
  1046.             var index = Math.random();
  1047.             index *= finalAds.length;
  1048.             index = Math.ceil(index);
  1049.  
  1050.  
  1051.             this.scoreAd = finalAds[index-1];
  1052.             height = this.scoreAd.height;
  1053.  
  1054.         }
  1055.  
  1056.  
  1057.     },
  1058.  
  1059.     updateAlertSlider: function(parameters) {
  1060.  
  1061.         var teamid = parameters.split(";")[0];
  1062.         var teamtitle = parameters.split(";")[1];
  1063.         var matchid = parameters.split(";")[2];
  1064.         var score1 = parameters.split(";")[3];
  1065.         var score2 = parameters.split(";")[4];
  1066.         var phase = parameters.split(";")[5];
  1067.         
  1068.  
  1069.         var match = this.getMatch(matchid);
  1070.  
  1071.         var league = this.getLeagueByMatch ( match );
  1072.         var leagueid = league.leagueID;
  1073.  
  1074.  
  1075.         if (match != -1) {
  1076.  
  1077.             var ff_alert_score1 = document.getElementById("ff_alert_score1");
  1078.             var ff_alert_score2 = document.getElementById("ff_alert_score2");
  1079.             var ff_alert_phase = document.getElementById("ff_alert_phase");
  1080.             ff_alert_score1.setAttribute("value", score1);
  1081.             ff_alert_score2.setAttribute("value", score2);
  1082.             if (phase && phase != 'undefined' && phase != 'null')
  1083.                 ff_alert_phase.setAttribute("value", phase);
  1084.             else
  1085.                 ff_alert_phase.setAttribute("value", "");
  1086.                 
  1087.             if (teamid == match.team1Id) {
  1088.                 ff_alert_score1.setAttribute("style", "font-size:18px;");
  1089.                 ff_alert_score2.setAttribute("style", "margin-top:3px;");
  1090.             }
  1091.                 
  1092.             if (teamid == match.team2Id) {
  1093.                 ff_alert_score2.setAttribute("style", "font-size:18px;");
  1094.                 ff_alert_score1.setAttribute("style", "margin-top:3px;");
  1095.             }
  1096.             
  1097.             match.team1Score = score1;
  1098.             match.team2Score = score2;
  1099.             match.phase = phase;
  1100.  
  1101.         }
  1102.  
  1103.         var slider = document.getElementById("ff_alert");
  1104.         slider.setAttribute("hidden", "false");
  1105.  
  1106.         var logo = document.getElementById("ff_alert_team_logo");
  1107.  
  1108.         if (this.inCache(teamid + "big.png"))
  1109.             var flagURL = "file://" + this.tmpDir + teamid + "big.png";
  1110.         else
  1111.             var flagURL = this.mediaURL + this.imagesSubdirectory + teamid + "big.png";
  1112.  
  1113.  
  1114.         logo.setAttribute("src", flagURL);
  1115.  
  1116.         var title = document.getElementById("ff_alert_team_title");
  1117.         title.setAttribute("value", teamtitle);
  1118.  
  1119.         var vbox = document.getElementById("ff_alert_vbox");    
  1120.         var url1 = this.redirectURL +"redirect/" + this.prefNode.getCharPref("partner") + "/6/" + matchid + "/" + this.prefNode.getCharPref("locale") + "/" + teamid+"?client_id="+this.getSerial();        
  1121.         vbox.setAttribute("onclick", "iFootieFox.visitWebpage(\""+ url1 +"\")");
  1122.  
  1123.         var url2 = this.redirectURL +"redirect/" + this.prefNode.getCharPref("partner") + "/7/" + matchid + "/" + this.prefNode.getCharPref("locale") + "/" + teamid+"?client_id="+this.getSerial();        
  1124.         var alert_partner = document.getElementById("ff_alert_partner");
  1125.         alert_partner.setAttribute("onclick", "iFootieFox.visitWebpage(\""+ url2 +"\")");
  1126.         
  1127.         // score ad
  1128.         
  1129.           this.scoreAd = null;
  1130.  
  1131.           this.determineAppropriateAd(parameters);
  1132.  
  1133.         var ad = this.scoreAd;
  1134.  
  1135.         var vbox = document.getElementById("ff_alert");
  1136.  
  1137.         var h = 108;
  1138.         var w = 200;
  1139.  
  1140.         var iframe = document.getElementById("ff_alert_banner");
  1141.         
  1142.         //adjust size for ad
  1143.         if (this.scoreAd != null) {
  1144.                 
  1145.             h = 108 + this.scoreAd.height;
  1146.             w = this.scoreAd.width;
  1147.  
  1148.             
  1149.             iframe.setAttribute("src", ad.url);
  1150.             iframe.setAttribute("style", "overflow:hidden;height:" + ad.height +"px;width:" + ad.width + "px;");
  1151.  
  1152.         } else {
  1153.             
  1154.             iframe.setAttribute("style", "overflow:hidden;height:108px;width:200px;");
  1155.         
  1156.         }
  1157.         
  1158.         
  1159.  
  1160.         vbox.setAttribute("style", "height:" + h +"px;width:" + w + "px;");
  1161.  
  1162.  
  1163.     },
  1164.  
  1165.     hideGoalAlert: function() {
  1166.  
  1167.         var slider = document.getElementById("ff_alert");
  1168.         slider.setAttribute("hidden", "true");
  1169.  
  1170.  
  1171.     },
  1172.     
  1173.  
  1174.     displayIFrame: function(id, url, w, h) {
  1175.  
  1176.         try {
  1177.             var idsstring = this.prefNode.getCharPref("iframes");
  1178.             var ids = idsstring.split(",");
  1179.             
  1180.             if (!inArray(id, ids)) {
  1181.             
  1182.                 //append new id at beginning
  1183.                 ids.unshift(id);
  1184.                 
  1185.                 var size = ids.length;
  1186.                 if (size > 5)
  1187.                     size = 5;
  1188.                 
  1189.                 var iframesstring = "";
  1190.                 for (var i=0;i<size;i++)
  1191.                     iframesstring += ids[i] + ","; 
  1192.                 
  1193.                 this.prefNode.setCharPref("iframes", iframesstring);
  1194.         
  1195.                 var banner = document.getElementById("ff_notification_banner");
  1196.                 banner.setAttribute("hidden", "false");
  1197.  
  1198.                 var iframe = document.getElementById("ff_iframe_banner");
  1199.                 iframe.setAttribute("src", url);
  1200.                 var style= "position:absolute;left:0px;border:none;overflow:hidden;width:"+ w +"px;height:"+ h +"px;";
  1201.                 iframe.setAttribute("style", style);
  1202.                 
  1203.             
  1204.             } 
  1205.             
  1206.             
  1207.         } catch (e) {
  1208.             
  1209.             footiefox_d_error(e);
  1210.         }
  1211.  
  1212.     },
  1213.  
  1214.     
  1215.     
  1216.     closeBanner: function() {
  1217.  
  1218.         var banner = document.getElementById("ff_notification_banner");
  1219.         banner.setAttribute("hidden", "true");
  1220.  
  1221.     },
  1222.  
  1223.     stopNotification: function() {
  1224.  
  1225.         var checkbox = document.getElementById("ff_notification_checkbox");
  1226.         if (checkbox.checked) {
  1227.  
  1228.             this.prefNode.setCharPref("latestversion", this.latestmajor + "." + this.latestminor);
  1229.  
  1230.         }
  1231.     },
  1232.  
  1233.     updateMyLeagues: function () {
  1234.  
  1235.         this.myLeagues = new Array();
  1236.         var leaguesToFollow = this.prefNode.getCharPref("leaguestofollow");
  1237.  
  1238.         if (leaguesToFollow!="") {
  1239.             leaguesToFollow = leaguesToFollow.split(",");
  1240.  
  1241.                 for (var x=0; x<leaguesToFollow.length-1; x++) {
  1242.                 if ( this.isNumber(leaguesToFollow[x]) )
  1243.                     this.myLeagues.push(leaguesToFollow[x]);
  1244.                 }
  1245.         }
  1246.  
  1247.     },
  1248.  
  1249.     isNumber: function(s){
  1250.  
  1251.         if (s.length == 0)
  1252.             return false;
  1253.         var i;
  1254.         for (i = 0; i < s.length; i++) {
  1255.  
  1256.             // check if current character is number
  1257.             var c = s.charAt(i);
  1258.             if (((c < "0") || (c > "9")))
  1259.             return false;
  1260.             if ( s == " " )
  1261.             return false;
  1262.         }
  1263.         return true;
  1264.         
  1265.     },
  1266.  
  1267.     updateMyTeams: function () {
  1268.  
  1269.         this.myTeams = new Array();
  1270.         var teamsToFollow = this.prefNode.getCharPref("teamstofollow");
  1271.  
  1272.         if (teamsToFollow!="") {
  1273.             teamsToFollow = teamsToFollow.split(",");
  1274.  
  1275.                 for (var x=0; x<teamsToFollow.length-1; x++) {
  1276.                         this.myTeams.push(teamsToFollow[x]);
  1277.                 }
  1278.         }
  1279.  
  1280.     },
  1281.     
  1282.     getNumberOfActiveMatches: function () {
  1283.  
  1284.         var leagues = this.myScoreboard;
  1285.         var activeMatches = 0;
  1286.  
  1287.         for ( var x = 0; x < leagues.length; x++ ) {
  1288.             
  1289.             var matches = leagues[x].matches;
  1290.  
  1291.             for ( var y = 0; y < matches.length; y++ ) {
  1292.                 
  1293.                 if (matches[y].status == "active")
  1294.                     activeMatches += 1;
  1295.             
  1296.             }
  1297.         
  1298.         }
  1299.         
  1300.         return activeMatches;
  1301.     },
  1302.     
  1303.     getNumberOfActiveMatchesInLeague: function () {
  1304.  
  1305.         var leagues = this.myScoreboard;
  1306.         var league = this.getLeagueByMatch ( this.selectedMatch );
  1307.  
  1308.  
  1309.         var matches = league.matches;
  1310.         var activeMatches = 0;
  1311.  
  1312.         for ( var x = 0; x < matches.length; x++ ) {
  1313.             
  1314.             var match = league.matches[x];
  1315.  
  1316.             
  1317.                 
  1318.             if (match.status == "active")
  1319.                 activeMatches += 1;
  1320.             
  1321.             
  1322.         
  1323.         }
  1324.         
  1325.         return activeMatches;
  1326.     },
  1327.  
  1328.     getNextMatch: function () {
  1329.  
  1330.         var leagues = this.myScoreboard;
  1331.         var currentMatch = false;
  1332.  
  1333.         for ( var x = 0; x < leagues.length; x++ ) {
  1334.  
  1335.             var matches = leagues[x].matches;
  1336.  
  1337.                 for ( var y = 0; y < matches.length; y++ ) {
  1338.  
  1339.                     var match = matches[y];
  1340.  
  1341.                 if ( currentMatch && match.team1Id > 0 )
  1342.                             return match;
  1343.  
  1344.  
  1345.                 var id = match.matchID;
  1346.  
  1347.                 if ( id == this.selectedMatch.matchID )
  1348.                     currentMatch = true;
  1349.             }
  1350.         }
  1351.  
  1352.         //current match last of list, return very first which is no placeholder
  1353.  
  1354.         for ( var x = 0; x < leagues.length; x++ ) {
  1355.  
  1356.             var matches = leagues[x].matches;
  1357.  
  1358.                 for ( var y = 0; y < matches.length; y++ ) {
  1359.  
  1360.                     var match = matches[y];
  1361.  
  1362.                 if ( match.team1Id > 0 )
  1363.                             return match;
  1364.               }
  1365.           }
  1366.  
  1367.           return null;
  1368.  
  1369.     },
  1370.     
  1371.     getNextActiveMatch: function () {
  1372.  
  1373.         var leagues = this.myScoreboard;
  1374.         var currentMatch = false;
  1375.  
  1376.         for ( var x = 0; x < leagues.length; x++ ) {
  1377.  
  1378.             var matches = leagues[x].matches;
  1379.  
  1380.                 for ( var y = 0; y < matches.length; y++ ) {
  1381.  
  1382.                     var match = matches[y];
  1383.  
  1384.                     if ( currentMatch && match.team1Id > 0 && match.status == "active")
  1385.                             return match;
  1386.  
  1387.  
  1388.                     var id = match.matchID;
  1389.  
  1390.                     if ( id == this.selectedMatch.matchID )
  1391.                         currentMatch = true;
  1392.             }
  1393.         }
  1394.  
  1395.         //current match last of list, return very first which is no placeholder
  1396.  
  1397.         for ( var x = 0; x < leagues.length; x++ ) {
  1398.  
  1399.             var matches = leagues[x].matches;
  1400.  
  1401.                 for ( var y = 0; y < matches.length; y++ ) {
  1402.  
  1403.                     var match = matches[y];
  1404.  
  1405.                 if ( match.team1Id > 0 && match.status == "active")
  1406.                             return match;
  1407.               }
  1408.           }
  1409.  
  1410.           return null;
  1411.  
  1412.     },
  1413.  
  1414.     getNextMatchInLeague: function () {
  1415.  
  1416.         var leagues = this.myScoreboard;
  1417.         var league = this.getLeagueByMatch ( this.selectedMatch );
  1418.  
  1419.  
  1420.         var matches = league.matches;
  1421.             var currentMatch = false;
  1422.  
  1423.             for ( var y = 0; y < matches.length; y++ ) {
  1424.  
  1425.                 var match = matches[y];
  1426.  
  1427.             if ( currentMatch )
  1428.                         return match;
  1429.  
  1430.             var id = match.matchID;
  1431.  
  1432.             if ( id == this.selectedMatch.matchID )
  1433.                 currentMatch = true;
  1434.  
  1435.         }
  1436.  
  1437.         //current match last of current league list
  1438.  
  1439.         for ( var y = 0; y < matches.length; y++ ) {
  1440.  
  1441.             var match = matches[y];
  1442.  
  1443.             if ( match.team1Id > 0 )
  1444.                         return match;
  1445.  
  1446.           }
  1447.  
  1448.         return null;
  1449.  
  1450.     },
  1451.  
  1452.  
  1453.     getNextActiveMatchInLeague: function () {
  1454.  
  1455.         var leagues = this.myScoreboard;
  1456.         var league = this.getLeagueByMatch ( this.selectedMatch );
  1457.  
  1458.  
  1459.         var matches = league.matches;
  1460.             var currentMatch = false;
  1461.  
  1462.             for ( var y = 0; y < matches.length; y++ ) {
  1463.  
  1464.                 var match = matches[y];
  1465.  
  1466.             if ( currentMatch && match.status == "active")
  1467.                         return match;
  1468.  
  1469.             var id = match.matchID;
  1470.  
  1471.             if ( id == this.selectedMatch.matchID )
  1472.                 currentMatch = true;
  1473.  
  1474.         }
  1475.  
  1476.         //current match last of current league list
  1477.  
  1478.         for ( var y = 0; y < matches.length; y++ ) {
  1479.  
  1480.             var match = matches[y];
  1481.  
  1482.             if ( match.team1Id > 0 && match.status == "active")
  1483.                         return match;
  1484.  
  1485.           }
  1486.  
  1487.         return null;
  1488.  
  1489.     },
  1490.  
  1491.     getMatch: function ( matchID ) {
  1492.  
  1493.         var leagues = this.myScoreboard;
  1494.         
  1495.         for ( var x = 0; x < leagues.length; x++ ) {
  1496.  
  1497.             var matches = leagues[x].matches;
  1498.  
  1499.  
  1500.                 for ( var y = 0; y < matches.length; y++ ) {
  1501.  
  1502.                 var match = matches[y];
  1503.                 var id = match.matchID;
  1504.  
  1505.  
  1506.                 if ( matchID == id )
  1507.                     return match;
  1508.             }
  1509.         }
  1510.  
  1511.         //match not found
  1512.         return -1;
  1513.  
  1514.     },
  1515.  
  1516.  
  1517.     getLeagueByID: function ( leagueID ) {
  1518.  
  1519.         var leagues = this.myScoreboard;
  1520.  
  1521.         for ( var x = 0; x < leagues.length; x++ ) {
  1522.  
  1523.             var league = leagues[x];
  1524.             var currentLeagueID = league.leagueID;
  1525.  
  1526.             if ( currentLeagueID == leagueID )
  1527.                 return league;
  1528.  
  1529.         }
  1530.  
  1531.         return -1;
  1532.  
  1533.     },
  1534.  
  1535.     getMatchesByLeagueId: function (leagueId)
  1536.     {
  1537.         var leagues = this.myScoreboard;
  1538.  
  1539.         for ( var x = 0; x < leagues.length; x++ ) {
  1540.             var currentLeagueId = leagues[x].leagueID;
  1541.  
  1542.             if ( currentLeagueId == leagueId )
  1543.                 return leagues[x].matches;
  1544.  
  1545.         }
  1546.  
  1547.         return null;
  1548.  
  1549.     },
  1550.  
  1551.     getLeagueByMatch: function ( match ) {
  1552.  
  1553.         var leagues = this.myScoreboard;
  1554.  
  1555.         for ( var x = 0; x < leagues.length; x++ ) {
  1556.  
  1557.             var matches = leagues[x].matches;
  1558.  
  1559.                 for ( var y = 0; y < matches.length; y++ ) {
  1560.  
  1561.                 var currentmatch = matches[y];
  1562.                 var id = currentmatch.matchID;
  1563.  
  1564.                 if ( match.matchID == id )
  1565.                     return leagues[x];
  1566.             }
  1567.         }
  1568.  
  1569.         //match not found
  1570.         return -1;
  1571.  
  1572.     },
  1573.  
  1574.     getCountryByLeague: function ( leagueId ) {
  1575.  
  1576.         var leaguesDataBundle = this.getCurrentLeaguesDataBundle();
  1577.  
  1578.         var country = -1;
  1579.  
  1580.         try {
  1581.             var leagueString = leaguesDataBundle.getString(leagueId);
  1582.             country = leagueString.split(":")[2];
  1583.             
  1584.         } catch (e) {
  1585.             footiefox_d_error("getCountryByLeague" + e);
  1586.         }
  1587.  
  1588.         return country;
  1589.  
  1590.     },
  1591.  
  1592.  
  1593.     displayMatch: function( match ) {
  1594.  
  1595.         //d("displayMatch: " + match.matchID);
  1596.         
  1597.         if (match == null) {
  1598.             
  1599.             match = this.getFirstMatch();
  1600.             this.selectedMatch = match;
  1601.             
  1602.         } 
  1603.  
  1604.         if ( match == null || match.team1Id < 0 )
  1605.             return;
  1606.  
  1607.         this.switchDisplay("match");
  1608.  
  1609.  
  1610.         this.selectedMatch = match;
  1611.  
  1612.         //score label
  1613.         var score = document.getElementById("statusbarpanel_score");
  1614.  
  1615.         var score1 = match.team1Score;
  1616.         var score2 = match.team2Score;
  1617.         
  1618.         var phase = "";
  1619.         
  1620.         if (match.phase != null && match.phase != "") {
  1621.             phase = " ("+match.phase+")";
  1622.         }
  1623.  
  1624.         if (match.status != "scheduled")
  1625.             score.setAttribute("value", score1 + ":" + score2 + phase);
  1626.         else
  1627.             score.setAttribute("value", "-:-");
  1628.  
  1629.         score.setAttribute("status", match.status);
  1630.         
  1631.         if (match.status=="scheduled")
  1632.             score.setAttribute("style","cursor: pointer;color:"+this.prefNode.getCharPref("color.scheduled"));
  1633.         if (match.status=="active")
  1634.             score.setAttribute("style","cursor: pointer;color:"+this.prefNode.getCharPref("color.active"));
  1635.         if (match.status=="finished")
  1636.             score.setAttribute("style","cursor: pointer;color:"+this.prefNode.getCharPref("color.finished"));
  1637.  
  1638.  
  1639.         //flags
  1640.         var flag1 = document.getElementById("statusbarpanel_flag1");
  1641.         var flag2 = document.getElementById("statusbarpanel_flag2");
  1642.  
  1643.         var teamID1 = match.team1Id;
  1644.         var teamID2 = match.team2Id;
  1645.  
  1646.         //check if logos are in cache and set urls accordingly
  1647.         if (this.inCache(teamID1 + ".png"))
  1648.             var flagURL1 = "file://" + this.tmpDir + teamID1 + ".png";
  1649.         else
  1650.             var flagURL1 = this.mediaURL + this.imagesSubdirectory + teamID1 + ".png";
  1651.  
  1652.         if (this.inCache(teamID2 + ".png"))
  1653.             var flagURL2 = "file://" + this.tmpDir + teamID2 + ".png";
  1654.         else
  1655.             var flagURL2 = this.mediaURL + this.imagesSubdirectory + teamID2 + ".png";
  1656.  
  1657.  
  1658.         flag1.setAttribute("src", flagURL1);
  1659.         flag2.setAttribute("src", flagURL2);
  1660.  
  1661.  
  1662.         var tooltip1 = match.team1Title;
  1663.         var tooltip2 = match.team2Title;
  1664.  
  1665.         flag1.setAttribute("tooltiptext", tooltip1);
  1666.         flag2.setAttribute("tooltiptext", tooltip2);
  1667.         
  1668.         
  1669.         var moreon = null;
  1670.         try {
  1671.             moreon = this.dictionary.getString("ff.popupmenu.teaminfo");
  1672.             } catch (e) {
  1673.             moreon ="More on";
  1674.             
  1675.         }
  1676.         var icon1menupopup_team = document.getElementById("icon1menupopup_team");
  1677.         icon1menupopup_team.setAttribute("label", moreon +" '"+ match.team1Title+"'");
  1678.  
  1679.         var icon2menupopup_team = document.getElementById("icon2menupopup_team");
  1680.         icon2menupopup_team.setAttribute("label", moreon +" '"+ match.team2Title+"'");
  1681.         
  1682.         var icon1menupopup_teamlocalization = document.getElementById("icon1menupopup_teamlocalization");
  1683.         var icon2menupopup_teamlocalization = document.getElementById("icon2menupopup_teamlocalization");
  1684.         
  1685.         if (this.prefNode.getCharPref("locale") == "de-DE") {
  1686.         
  1687.             icon1menupopup_teamlocalization.setAttribute("collapsed","true");
  1688.             icon1menupopup_teamlocalization.setAttribute("hidden","true");
  1689.             icon2menupopup_teamlocalization.setAttribute("collapsed","true");
  1690.             icon2menupopup_teamlocalization.setAttribute("hidden","true");
  1691.             
  1692.         } else {
  1693.                        
  1694.             icon1menupopup_teamlocalization.setAttribute("collapsed","false");
  1695.             icon1menupopup_teamlocalization.setAttribute("hidden","false");
  1696.             icon2menupopup_teamlocalization.setAttribute("collapsed","false");
  1697.             icon2menupopup_teamlocalization.setAttribute("hidden","false");
  1698.         
  1699.         }
  1700.         
  1701.         var currentleague = this.getLeagueByMatch(match);
  1702.         
  1703.         var ff_popupmenu_matchreport1 = document.getElementById("ff_popupmenu_matchreport1");
  1704.         var ff_popupmenu_matchreport2 = document.getElementById("ff_popupmenu_matchreport2");
  1705.         
  1706.         var partner = this.checkForLeaguePartner(currentleague.leagueID);       
  1707.         
  1708.         var statusbar = document.getElementById("statusbarpanel_partner_logo");
  1709.         
  1710.         if (partner==-1) {
  1711.             partner = this.prefNode.getCharPref("partner");
  1712.         }
  1713.         
  1714.         statusbar.setAttribute("src", "chrome://footiefox/skin/"+partner+"/statusbar.png");
  1715.         statusbar.removeAttribute("onclick");
  1716.         statusbar.setAttribute("onclick", "iFootieFox.bannerClicked(event, "+partner+")");
  1717.         
  1718.         flag1.removeAttribute("onclick");
  1719.         flag1.setAttribute("onclick", "iFootieFox.icon1Clicked(event,"+partner+")");
  1720.         flag2.removeAttribute("onclick");
  1721.         flag2.setAttribute("onclick", "iFootieFox.icon2Clicked(event,"+partner+")");
  1722.         ff_popupmenu_matchreport1.removeAttribute("oncommand");
  1723.         ff_popupmenu_matchreport1.setAttribute("oncommand","iFootieFox.contextMenuReportClicked1("+partner+");");
  1724.         ff_popupmenu_matchreport2.removeAttribute("oncommand");
  1725.         ff_popupmenu_matchreport2.setAttribute("oncommand","iFootieFox.contextMenuReportClicked2("+partner+");");
  1726.  
  1727.         var score = document.getElementById("statusbarpanel_score");
  1728.         score.removeAttribute("tooltiptext");
  1729.  
  1730.  
  1731.  
  1732.     },
  1733.     
  1734.     checkForLeaguePartner: function (leagueid) {
  1735.     
  1736.         var partnersEnum = this.partners.strings;
  1737.         var index = -1;
  1738.         while (partnersEnum.hasMoreElements()) {
  1739.         
  1740.             try {
  1741.  
  1742.                 var element = partnersEnum.getNext();
  1743.  
  1744.                 var key = element.QueryInterface(Components.interfaces.nsIPropertyElement).key;
  1745.                 var value = element.QueryInterface(Components.interfaces.nsIPropertyElement).value;
  1746.                     
  1747.                 try {
  1748.                     var leaguesValue = value.split(":")[2];
  1749.                     
  1750.                     var leagues = leaguesValue.split(",");
  1751.                     
  1752.                     for (var i=0;i<leagues.length;i++) {
  1753.                         var league = leagues[i];
  1754.                         
  1755.                         if (league == leagueid)
  1756.                             return key;
  1757.                     }
  1758.                     
  1759.                 } catch (e) {
  1760.                     continue;
  1761.                 }
  1762.                 
  1763.                 
  1764.  
  1765.             } catch(ex){
  1766.                         footiefox_d_error(ex); continue;
  1767.             }
  1768.         }
  1769.         
  1770.         try {
  1771.             return this.prefNode.getCharPref("partner");
  1772.         } catch (e) {
  1773.             footiefox_d_error("checkForLeaguePartner: "+ e);
  1774.         }
  1775.         return -1;
  1776.     
  1777.     },
  1778.  
  1779.     inCache: function (filename) {
  1780.  
  1781.         if (this.tmpDir == "")
  1782.             return false;
  1783.  
  1784.         var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  1785.         file.initWithPath(this.tmpDir + filename);
  1786.  
  1787.         if (file.exists())
  1788.             return true;
  1789.         else
  1790.             return false;
  1791.  
  1792.     },
  1793.  
  1794.     updateData: function (matchDiffs, awake) {
  1795.  
  1796.         //footiefox_d_message("updateData");
  1797.  
  1798.         var delay = 0;
  1799.         var goal = false;
  1800.  
  1801.         for (var x=0; x<matchDiffs.length; x++) {
  1802.  
  1803.             var matchDiff = matchDiffs[x];
  1804.  
  1805.             var matchid = matchDiff.matchId;
  1806.             
  1807.             var currentmatchid = this.selectedMatch.matchID;
  1808.             var currentleague = this.getLeagueByMatch(this.selectedMatch);
  1809.             var currentleagueid = currentleague.leagueID;
  1810.  
  1811.             var match = this.getMatch( matchid );
  1812.             var league = this.getLeagueByMatch(match);
  1813.             var leagueid = league.leagueID;
  1814.             
  1815.             var alertmode = this.prefNode.getCharPref("alertmode");
  1816.  
  1817.             var showslider = this.prefNode.getBoolPref("showslider");
  1818.  
  1819.             this.checkFirstExtension();
  1820.  
  1821.  
  1822.             if ( this.firstExtension && showslider && !awake )
  1823.                 if ( (alertmode == "all") || (alertmode == "game" && currentmatchid == matchid )
  1824.                 || (alertmode == "league" && currentleagueid == leagueid ) ) {
  1825.  
  1826.                     if (matchDiff.teamId != null) {
  1827.                         sliders.push(matchDiff);
  1828.  
  1829.                         goal = true;
  1830.                     }
  1831.                 }
  1832.                 
  1833.                 leagueIndex = this.getLeagueIndex(leagueid);
  1834.                 
  1835.                 matchIndex = this.getMatchIndex(leagueid, matchid);
  1836.                 
  1837.                 //update scoreboard
  1838.                 this.myScoreboard[leagueIndex].matches[matchIndex].status = matchDiff.status;
  1839.                 this.myScoreboard[leagueIndex].matches[matchIndex].team1Score = matchDiff.team1Score;
  1840.                 this.myScoreboard[leagueIndex].matches[matchIndex].team2Score = matchDiff.team2Score;
  1841.                 this.myScoreboard[leagueIndex].matches[matchIndex].phase = matchDiff.phase;
  1842.  
  1843.         }
  1844.  
  1845.  
  1846.         //play sound only once, even if there are a couple of goals with this update
  1847.         if (goal == true && this.prefNode.getBoolPref("playalarm") && !awake) {
  1848.  
  1849.             var soundfileURL = this.prefNode.getCharPref("alarmfile");
  1850.             playAlarmSound(soundfileURL);
  1851.  
  1852.         }
  1853.  
  1854.         this.displayMatch(this.selectedMatch);
  1855.         
  1856.         if (sliders.length > 0) {
  1857.             this.displayGoalAlert();
  1858.         }
  1859.  
  1860.  
  1861.  
  1862.  
  1863.     },
  1864.     
  1865.    getMatchPhase: function (id) {
  1866.         
  1867.         switch (id) {
  1868.             case 3: 
  1869.                 return this.translateById("ff.notice.overtime", "AET");
  1870.                 break;
  1871.                 
  1872.             case 4: 
  1873.                 return this.translateById("ff.notice.overtime", "AET");
  1874.                 break;
  1875.                    
  1876.             case 5: 
  1877.                 return this.translateById("ff.notice.penalties", "Pens");
  1878.                 break;       
  1879.                    
  1880.             default:
  1881.                 return "";
  1882.         
  1883.         }
  1884.    
  1885.    },
  1886.     
  1887.     getLeagueIndex: function (leagueid) {
  1888.         
  1889.         
  1890.         try {
  1891.             for ( var i=0; i<this.myScoreboard.length; i++ ) {
  1892.                 
  1893.                 if (this.myScoreboard[i].leagueID == leagueid)
  1894.                     return i;
  1895.             }
  1896.         } catch (e) {
  1897.             footiefox_d_error("getLeagueIndex: "+ e);
  1898.             return -1;
  1899.         }
  1900.         
  1901.         return null;
  1902.     
  1903.     },
  1904.     
  1905.     getMatchIndex: function (leagueid, matchid) {
  1906.     
  1907.         try {
  1908.             league = this.getLeagueByID(leagueid);
  1909.  
  1910.             for ( var i=0; i<league.matches.length; i++ )
  1911.                 if (league.matches[i].matchID == matchid)
  1912.                     return i;
  1913.             
  1914.         } catch (e) {
  1915.             footiefox_d_error("getMatchIndex: "+ e);
  1916.             return -1;
  1917.         }
  1918.         
  1919.         return null;
  1920.     
  1921.     },
  1922.  
  1923.     checkFirstExtension: function () {
  1924.  
  1925.         //detect if maybe first extension was destroyed
  1926.         var observerService = Components.classes["@mozilla.org/observer-service;1"]
  1927.             .getService(Components.interfaces.nsIObserverService);
  1928.  
  1929.         var extensionslist = observerService.enumerateObservers("footiefoxExtension");
  1930.             //no footiefox registered yet - this is the "first extension"
  1931.         if ( !extensionslist.hasMoreElements() ) {
  1932.  
  1933.             this.firstExtension = true;
  1934.             observerService.addObserver(this, "footiefoxExtension", false);
  1935.         }
  1936.  
  1937.     },
  1938.  
  1939.         //checks if this window is visible
  1940.     checkWindowMaximized: function () {
  1941.  
  1942.         var observerService = Components.classes["@mozilla.org/observer-service;1"]
  1943.             .getService(Components.interfaces.nsIObserverService);
  1944.  
  1945.         var maximizedlist = observerService.enumerateObservers("footiefoxWindowMaximized");
  1946.  
  1947.  
  1948.         //this window is visible
  1949.         footiefox_d_message("this windows has focus:"+windowfocused);
  1950.  
  1951.         if ( windowfocused )
  1952.             if ( !maximizedlist.hasMoreElements() ) {
  1953.  
  1954.                 observerService.addObserver(this, "footiefoxWindowMaximized", false);
  1955.             }
  1956.  
  1957.     },
  1958.  
  1959.  
  1960.     goalAlert: function (teamId, teamTitle) {
  1961.         
  1962.         FootieFoxSliderAction = false;
  1963.  
  1964.         try {
  1965.             var alertService = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);
  1966.  
  1967.             var teamString = teamTitle;
  1968.  
  1969.                 if (this.inCache(teamId + "big.png"))
  1970.                 var url = "file://" + this.tmpDir + teamId + "big.png";
  1971.             else
  1972.                 var url = this.mediaURL + this.imagesSubdirectory +  teamId + "big.png";
  1973.  
  1974.             var slogan = "FOOTIEFOX";
  1975.             try {
  1976.  
  1977.                     slogan = this.dictionary.getString("ff.alerts.goal") + "       ";
  1978.             } catch (e) {
  1979.                 footiefox_d_error("goalAlert"+e);
  1980.             }
  1981.             
  1982.             var listener = {
  1983.                   observe: function(subject, topic, data) {
  1984.                     iFootieFox.displayGoalAlert();
  1985.                 }
  1986.             }
  1987.  
  1988.             alertService.showAlertNotification(url, slogan, teamString, false, "", listener);
  1989.  
  1990.  
  1991.  
  1992.         } catch (e) { footiefox_d_error(e);}
  1993.  
  1994.     },
  1995.  
  1996.     messageAlert: function () {
  1997.  
  1998.         var url = this.messages[ this.lastMessage ].url;
  1999.         var linkurl = this.messages[ this.lastMessage ].linkurl;
  2000.  
  2001.         var linktext = this.messages[ this.lastMessage ].linktext;
  2002.         
  2003.         this.lastMessage +=1;
  2004.  
  2005.  
  2006.         try {
  2007.             var alertService = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);
  2008.  
  2009.                         var fileName = url.substring(url.lastIndexOf('/')+1, url.length);
  2010.  
  2011.             if (this.inCache(fileName))
  2012.                 var url = "file://" + this.tmpDir + "/" + fileName;
  2013.  
  2014.             alertService.showAlertNotification(url, "", linktext, true, "", this.myObservers);
  2015.  
  2016.         } catch (e) {}
  2017.  
  2018.     },
  2019.  
  2020.  
  2021.     removeMenu: function() {
  2022.  
  2023.         //d("removeMenu");
  2024.  
  2025.         //remove dynamic menu items
  2026.         var menupopup_mainmenupopup = document.getElementById("menupopup_mainmenupopup");
  2027.                 var menuitems = null;
  2028.         try {
  2029.             menuitems = menupopup_mainmenupopup.getElementsByTagName("menu");
  2030.         } catch (e) {}
  2031.  
  2032.         while ( menuitems.length > 0 ) {
  2033.             menuitems = menupopup_mainmenupopup.getElementsByTagName("menu");
  2034.             var child = menuitems[0];
  2035.             menupopup_mainmenupopup.removeChild(child);
  2036.         }
  2037.  
  2038.     },
  2039.  
  2040.  
  2041.     highlightMenuItem: function(element) {
  2042.  
  2043.         element.setAttribute("style", "background:#0A246A;color:white");
  2044.         var labels = element.getElementsByTagName("label");
  2045.         for (var x = 0; x < labels.length; x++) {
  2046.             var label = labels[x];
  2047.             label.setAttribute("style", "color:white");
  2048.         }
  2049.  
  2050.     },
  2051.  
  2052.         unhighlightMenuItem: function(element) {
  2053.  
  2054.         element.removeAttribute("style");
  2055.         var labels = element.getElementsByTagName("label");
  2056.         for (var x = 0; x < labels.length; x++) {
  2057.             var label = labels[x];
  2058.             
  2059.             label.setAttribute("style", "color:black");
  2060.             
  2061.             if (label.getAttribute("status")=="scheduled") {
  2062.                     label.setAttribute("style","color:"+this.prefNode.getCharPref("color.scheduled"));
  2063.                  
  2064.                 }
  2065.                 if (label.getAttribute("status")=="active") {
  2066.                     label.setAttribute("style","color:"+this.prefNode.getCharPref("color.active"));
  2067.                   
  2068.                 }
  2069.                 if (label.getAttribute("status")=="finished") {
  2070.                     label.setAttribute("style","color:"+this.prefNode.getCharPref("color.finished"));
  2071.                    
  2072.                 }
  2073.         }
  2074.  
  2075.     },
  2076.  
  2077.     hideMenu: function() {
  2078.  
  2079.         var mainPopupSet = document.getElementById("menupopup_mainmenupopup");
  2080.         mainPopupSet.hidePopup();
  2081.  
  2082.     },
  2083.     
  2084.     getCurrentLeaguesDataBundle: function() {
  2085.     
  2086.         var leaguesDataBundleUpdated = document.getElementById("leagues-data-bundle-updated");
  2087.  
  2088.         var leaguesDataBundle = null;
  2089.         
  2090.         //updated leagues.dat valid
  2091.         if ( leaguesDataBundleUpdated.hasAttribute("src") )
  2092.             leaguesDataBundle = leaguesDataBundleUpdated;
  2093.         //updated leagues.dat corrupt, take inbuilt leagues.dat
  2094.         else
  2095.             leaguesDataBundle = document.getElementById("leagues-data-bundle");
  2096.         
  2097.         return leaguesDataBundle;
  2098.     
  2099.     },
  2100.  
  2101.      buildMenu: function() {
  2102.         
  2103.         footiefox_d_message("buildMenu");
  2104.         
  2105.         // don't rebuild when menu is currently shown
  2106.         if (this.menu_visible) {
  2107.             return;
  2108.         }
  2109.         
  2110.         //clear old menu entries
  2111.         this.removeMenu();
  2112.  
  2113.         var leaguesDataBundle = this.getCurrentLeaguesDataBundle();
  2114.  
  2115.         for (var x=0; x < this.myScoreboard.length; x++) {
  2116.  
  2117.             var league = this.myScoreboard[x];
  2118.             
  2119.             //////////menuitem for league title/////////////
  2120.             
  2121.             var mainPopupSet = document.getElementById("menupopup_mainmenupopup");
  2122.             //append menu right after creation!
  2123.             var menu = document.createElement("menu");
  2124.             mainPopupSet.appendChild(menu);
  2125.             
  2126.             mainPopupSet.setAttribute("onpopupshown", "iFootieFox.menu_visible = true;");
  2127.             mainPopupSet.setAttribute("onpopuphidden", "iFootieFox.menu_visible = false;");
  2128.             
  2129.             var countryshort = this.getLeagueCountryShort(league.leagueID); 
  2130.             if ( countryshort != "" )
  2131.                 countryshort = " (" + countryshort + ")";
  2132.             
  2133.             var label = this.getLocalLeagueTitle(league.leagueID) + countryshort;
  2134.             
  2135.  
  2136.             menu.setAttribute("label", label );
  2137.             menu.setAttribute("id", league.leagueID);
  2138.  
  2139.             var menupopup = document.createElement("menupopup");
  2140.             menupopup.setAttribute("id", league.leagueID);
  2141.             menupopup.setAttribute("class", "footiefox_match_list");
  2142.             
  2143.             menu.appendChild(menupopup);
  2144.             
  2145.             
  2146.             /////////entry for each match////////////
  2147.             
  2148.             var menulayout = this.prefNode.getCharPref("menulayout");
  2149.             var showscores = this.prefNode.getBoolPref("menuitemsshowscores");
  2150.             var showdate = this.prefNode.getBoolPref("menuitemsshowdate");
  2151.  
  2152.             var olddate = null;
  2153.             
  2154.             
  2155.             var games = league.matches;
  2156.             
  2157.             var groups = new Array();
  2158.             var groupItems = new Array();
  2159.             
  2160.             for (var i=0; i<games.length; i++) {
  2161.                 
  2162.                 var game = games[i];
  2163.                 var group_id = 0;
  2164.                 
  2165.                 if (typeof(game.tournament_group) != 'undefined')
  2166.                     group_id = game.tournament_group;
  2167.                 
  2168.                 var group = null;
  2169.                 for ( var j=0; j<groups.length; j++ ) {
  2170.                     var current_group = groups[j];
  2171.                     if (current_group.id == group_id) {
  2172.                         group = current_group;
  2173.                         break;
  2174.                     }
  2175.                 }
  2176.                 
  2177.                 if (group) {
  2178.                 
  2179.                     group.games.push(game);
  2180.                 
  2181.                 } else {
  2182.                     
  2183.                     
  2184.                     group = new Object();
  2185.                     
  2186.                     group.id = group_id;
  2187.                     
  2188.                     
  2189.                     group.games = new Array();
  2190.                     group.games.push(game);
  2191.                     
  2192.                     groups.push(group);
  2193.                     
  2194.                 }
  2195.                 
  2196.                 
  2197.             }
  2198.             
  2199.             var groupend = true;
  2200.             
  2201.             for (var zz = 0; zz < groups.length; zz++) {
  2202.                 
  2203.                 var scoreboard_vbox = document.createElement("vbox");;
  2204.             
  2205.                 var group = groups[zz];
  2206.                 var groupmenupopup = null;
  2207.                 
  2208.                 var games = group.games;
  2209.                 
  2210.                 
  2211.                 for (var y = 0; y < games.length; y++) {
  2212.                     
  2213.                     var game = games[y];
  2214.                     
  2215.                     var hbox = document.createElement("hbox");
  2216.  
  2217.  
  2218.                     if (showdate) {
  2219.  
  2220.                         var date = new Date(game.startTime);
  2221.  
  2222.                         var localdate = "";
  2223.                         if (date != null)
  2224.                             localdate = date.toLocaleDateString();
  2225.  
  2226.  
  2227.                         var timebox = document.createElement("vbox");
  2228.                         timebox.setAttribute("pack", "center");
  2229.  
  2230.                         var timelabel = document.createElement("label");
  2231.                         var timestring = date.toLocaleTimeString();
  2232.                         timestring = timestring.replace(/:\d\d([^:]|$)/, " ");
  2233.  
  2234.                         timelabel.setAttribute("value", timestring);
  2235.                         timelabel.setAttribute("id", "kickofftime");
  2236.                         timebox.appendChild(timelabel);
  2237.                         hbox.appendChild(timebox);
  2238.  
  2239.                         //skip in case date exists already
  2240.                         var datenew = true;
  2241.                         try {
  2242.  
  2243.                             var elements = scoreboard_vbox.getElementsByTagName("label");
  2244.  
  2245.                             for (var z=0; z<elements.length; z++)
  2246.                                 if (elements[z].getAttribute("value") == localdate) {
  2247.                                     datenew = false;
  2248.                                     break;
  2249.                                 }
  2250.  
  2251.                         } catch(e) {footiefox_d_error("buildMenu"+e);}
  2252.  
  2253.  
  2254.                         if (datenew && date != null) {
  2255.  
  2256.                             var datebox = document.createElement("hbox");
  2257.                             datebox.setAttribute("id", "datebox");
  2258.                             var datelabel = document.createElement("label");
  2259.  
  2260.                             datelabel.setAttribute("value", localdate);
  2261.                             datelabel.setAttribute("id", "kickoffdate");
  2262.                             datebox.appendChild(datelabel);
  2263.                             scoreboard_vbox.appendChild(datebox);
  2264.  
  2265.  
  2266.                             var menuseparator = document.createElement("menuseparator");
  2267.                             menuseparator.setAttribute("id", "dateunderline");
  2268.                             scoreboard_vbox.appendChild( menuseparator );
  2269.                         }
  2270.                     }
  2271.  
  2272.                     var teamtitle1 = game.team1Title;
  2273.                     var teamtitle2 = game.team2Title
  2274.  
  2275.                     var score1 = game.team1Score;
  2276.                     var score2 = game.team2Score;
  2277.  
  2278.                     if ( game.status == "scheduled" ) {
  2279.                         score1 = "-";
  2280.                         score2 = "-";
  2281.                     }
  2282.  
  2283.  
  2284.  
  2285.  
  2286.                     hbox.setAttribute ("id", game.matchID );
  2287.                     hbox.setAttribute ("onmouseover", "iFootieFox.highlightMenuItem(this);");
  2288.                     hbox.setAttribute ("onmouseout", "iFootieFox.unhighlightMenuItem(this);");
  2289.                     hbox.setAttribute ("onclick", "iFootieFox.displayMatch(iFootieFox.getMatch(this.id));iFootieFox.hideMenu();");
  2290.                     hbox.setAttribute ("pack", "center");
  2291.  
  2292.                     var hboxscore = document.createElement("hbox");
  2293.                     hboxscore.setAttribute ("pack", "center");
  2294.                     hboxscore.setAttribute ("id", "score");
  2295.                     hboxscore.setAttribute ("status", game.status );
  2296.                             
  2297.                     
  2298.                             
  2299.                     hboxscore.setAttribute ("style", "width:45px;");
  2300.  
  2301.  
  2302.                     var vboxscore = document.createElement("vbox");
  2303.                     vboxscore.setAttribute("style", "width:25px");
  2304.                     vboxscore.setAttribute("pack", "center");
  2305.                     vboxscore.setAttribute("align", "right");
  2306.  
  2307.                     var labelscore = document.createElement("label");
  2308.                     labelscore.setAttribute("style", "margin:0px;width:20px;");
  2309.                     
  2310.                     if (game.status=="scheduled") {
  2311.                         labelscore.setAttribute("style","color:"+this.prefNode.getCharPref("color.scheduled"));
  2312.                         labelscore.setAttribute("status", "scheduled");
  2313.                     }
  2314.                     if (game.status=="active") {
  2315.                         labelscore.setAttribute("style","color:"+this.prefNode.getCharPref("color.active"));
  2316.                         labelscore.setAttribute("status", "active");
  2317.                     }
  2318.                     if (game.status=="finished") {
  2319.                         labelscore.setAttribute("style","color:"+this.prefNode.getCharPref("color.finished"));
  2320.                         labelscore.setAttribute("status", "finished");
  2321.                     }
  2322.                         
  2323.                     labelscore.setAttribute("pack", "center");
  2324.  
  2325.  
  2326.                     var phase = " ";
  2327.                     if (game.phase) {
  2328.                         phase = " ("+game.phase+")";
  2329.                     }
  2330.         
  2331.                     var scorestring = "";
  2332.                     
  2333.                     var score1length = 0;
  2334.                     var score2length = 0;
  2335.                     
  2336.                     try {
  2337.                         
  2338.                         score1length = score1.toString().length;    
  2339.  
  2340.                     } catch (e) {}
  2341.                     
  2342.                     
  2343.                     
  2344.                     if (score1length < 2)
  2345.                         scorestring += " ";
  2346.                     
  2347.                     scorestring += score1 + ":" + score2 + phase;
  2348.  
  2349.                     
  2350.  
  2351.                     labelscore.setAttribute("value", scorestring);
  2352.                     vboxscore.appendChild( labelscore );
  2353.  
  2354.                     hboxscore.appendChild (vboxscore);
  2355.  
  2356.                     var vboxvs = document.createElement("vbox");
  2357.                     vboxvs.setAttribute ("pack", "center");
  2358.                     vboxvs.setAttribute ("style", "max-width: 50px");
  2359.  
  2360.                     var labelvs = document.createElement("label");
  2361.                     labelvs.setAttribute("value", "vs.");
  2362.                     labelvs.setAttribute("id", "vs");
  2363.                     vboxvs.appendChild (labelvs);
  2364.  
  2365.                     var vboxlabelteamtitle1 = document.createElement("vbox");
  2366.                     var labelteamtitle1 = document.createElement("label");
  2367.                     labelteamtitle1.setAttribute("value", teamtitle1);
  2368.                     labelteamtitle1.setAttribute("id", "teamtitle");
  2369.                     vboxlabelteamtitle1.setAttribute("pack", "center");
  2370.                     vboxlabelteamtitle1.setAttribute("flex", "2");
  2371.                     vboxlabelteamtitle1.appendChild(labelteamtitle1);
  2372.  
  2373.                     var vboxlabelteamtitle2 = document.createElement("vbox");
  2374.                     var labelteamtitle2 = document.createElement("label");
  2375.                     labelteamtitle2.setAttribute("value", teamtitle2);
  2376.                     labelteamtitle2.setAttribute("id", "teamtitle");
  2377.                     vboxlabelteamtitle2.setAttribute("pack", "center");
  2378.                     vboxlabelteamtitle2.setAttribute("flex", "2");
  2379.                     vboxlabelteamtitle2.appendChild(labelteamtitle2);
  2380.  
  2381.  
  2382.  
  2383.                     var img1 = document.createElement("image");
  2384.                     if (this.inCache(game.team1Id + ".png"))
  2385.                         var src1 = "file://" + this.tmpDir + game.team1Id + ".png";
  2386.                     else
  2387.                         var src1 = this.mediaURL + this.imagesSubdirectory + game.team1Id + ".png";
  2388.  
  2389.                     img1.setAttribute("src", src1);
  2390.                     img1.setAttribute("width", "30px");
  2391.                     if ( menulayout == "logos" )
  2392.                         img1.setAttribute("tooltiptext", teamtitle1);
  2393.  
  2394.                     var img2 = document.createElement("image");
  2395.                     if (this.inCache(game.team2Id + ".png"))
  2396.                         var src2 = "file://" + this.tmpDir + game.team2Id + ".png";
  2397.                     else
  2398.                         var src2 = this.mediaURL + this.imagesSubdirectory + game.team2Id + ".png";
  2399.  
  2400.                     img2.setAttribute("src", src2);
  2401.                     img2.setAttribute("width", "30px");
  2402.                     if ( menulayout == "logos" )
  2403.                         img2.setAttribute("tooltiptext", teamtitle2);
  2404.  
  2405.  
  2406.                     if ( menulayout != "titles" )
  2407.                         hbox.appendChild (img1);
  2408.  
  2409.                     if ( menulayout != "logos" )
  2410.                         hbox.appendChild (vboxlabelteamtitle1);
  2411.  
  2412.                     if ( showscores ) {
  2413.                         hbox.appendChild (hboxscore);
  2414.                     } else {
  2415.                         hbox.appendChild (vboxvs);
  2416.                     }
  2417.  
  2418.                     if ( menulayout != "logos" )
  2419.                         hbox.appendChild (vboxlabelteamtitle2);
  2420.                         if ( menulayout != "titles" )
  2421.                             hbox.appendChild (img2);
  2422.  
  2423.                     scoreboard_vbox.appendChild(hbox);
  2424.  
  2425.                     if ( y < games.length - 1 ) {
  2426.  
  2427.                         var spacerbox = document.createElement("hbox");
  2428.                         var label = document.createElement("label");
  2429.                         spacerbox.appendChild (label);
  2430.                         scoreboard_vbox.appendChild(spacerbox);
  2431.                     }
  2432.  
  2433.                 }
  2434.                 
  2435.                 if (groups.length > 1) {
  2436.                     
  2437.                     var groupmenu = document.createElement("menu");
  2438.                     //menupopup.appendChild(groupmenu);
  2439.                     
  2440.                     groupmenu.setAttribute("id", group.id);
  2441.                     
  2442.                     
  2443.                     
  2444.                     //do some translation
  2445.                     var glabel = group.id.replace(/Gruppe/,this.translateById('ff.wm.group', 'Group'));
  2446.                     glabel = glabel.replace(/Viertelfinale/,this.translateById('ff.wm.quarterfinals', 'Quarter-finals'));
  2447.                     glabel = glabel.replace(/Halbfinale/,this.translateById('ff.wm.semifinals', 'Semi-finals'));
  2448.                     glabel = glabel.replace(/Finale/,this.translateById('ff.wm.final', 'Final'));
  2449.                     
  2450.                     
  2451.                     
  2452.                     groupmenu.setAttribute("label", glabel);
  2453.                     
  2454.                     var groupmenupopup = document.createElement("menupopup");
  2455.                     groupmenu.appendChild(groupmenupopup);
  2456.                     
  2457.                     groupmenupopup.setAttribute("id", group.id);
  2458.                     
  2459.                     groupmenupopup.appendChild(scoreboard_vbox);
  2460.                     
  2461.                     
  2462.                     // reorder groups
  2463.                     if (group.id.indexOf("Gruppe") == -1 && groupend) {                    
  2464.                         groupItems.reverse();
  2465.                         groupend = false;
  2466.                     }
  2467.  
  2468.                     
  2469.                     if (group.id.indexOf("Gruppe") == -1 && zz < groups.length) {
  2470.                         groupItems.push(document.createElement("menuseparator"));
  2471.                     } 
  2472.                     
  2473.                     
  2474.                         
  2475.                     groupItems.push(groupmenu);
  2476.                 
  2477.                     
  2478.                     
  2479.                 } else {
  2480.                     menupopup.appendChild(scoreboard_vbox);
  2481.                 }
  2482.                 
  2483.             }
  2484.             
  2485.             groupItems.reverse();
  2486.                         
  2487.             for (var ii=0; ii<groupItems.length; ii++) 
  2488.                 menupopup.appendChild(groupItems[ii]);
  2489.             
  2490.             //insert table link
  2491.             if (!league.is_tournament) {
  2492.             
  2493.                 var menusep = document.createElement("menuseparator");
  2494.                 menupopup.appendChild(menusep);
  2495.             
  2496.             
  2497.                 var tablelink = document.createElement("menuitem");
  2498.                 tablelink.setAttribute("id", "tablelink");
  2499.                 tablelink.setAttribute("style", "font-weight:normal;");
  2500.                 var tablelabel = "Display current league table for";
  2501.                 try {
  2502.                     tablelabel = this.dictionary.getString("ff.popupmenu.table");
  2503.                 
  2504.                 } catch(e) {
  2505.                     footiefox_d_message("buildMenu: Translation of table link failed "+e);
  2506.                 }
  2507.                 
  2508.                 tablelabel += " "+ this.getLocalLeagueTitle(league.leagueID) + " ...";
  2509.                 
  2510.                 try {
  2511.                     tablelink.setAttribute("label", tablelabel);
  2512.                     var partnerid = this.checkForLeaguePartner(league.leagueID);  
  2513.                     
  2514.                     tablelink.setAttribute("oncommand", "iFootieFox.openLeagueTable("+games[0].matchID+",15,"+partnerid+")");
  2515.                     menupopup.appendChild(tablelink);
  2516.                 } catch (e) {
  2517.                     footiefox_d_error(e);
  2518.                 }
  2519.                 
  2520.             }
  2521.  
  2522.         }
  2523.  
  2524.         this.sortMatchesByTime();
  2525.  
  2526.  
  2527.         return;
  2528.     },
  2529.  
  2530.     getLocalLeagueTitle: function(leagueID) {
  2531.     
  2532.         var leaguesDataBundle = this.getCurrentLeaguesDataBundle();
  2533.         var leaguesDataString = null;
  2534.  
  2535.         try {
  2536.                 leaguesDataString = leaguesDataBundle.getString(leagueID);
  2537.                 
  2538.         } catch (e) {
  2539.  
  2540.             footiefox_d_error("Failed to match league ID: " + leagueID);
  2541.  
  2542.         }
  2543.         
  2544.         var leaguetitle = "No title";
  2545.         try {
  2546.             leaguetitle = leaguesDataString.split(":")[0];
  2547.         } catch (e) {}
  2548.         
  2549.         var intltitle = null;
  2550.         try {
  2551.             intltitle = leaguesDataString.split(":")[4];
  2552.         } catch (e) {}
  2553.         
  2554.         var loc = this.prefNode.getCharPref("locale");
  2555.         
  2556.         if ((intltitle != null) && (intltitle !="") && (loc != "de-DE")) {
  2557.         
  2558.             finalLeagueTitle = intltitle;
  2559.         } else {
  2560.             finalLeagueTitle = leaguetitle;
  2561.         }
  2562.     
  2563.         return finalLeagueTitle;
  2564.     
  2565.     },
  2566.     
  2567.     getLeagueCountryShort: function(leagueID) {
  2568.     
  2569.         var leaguesDataBundle = this.getCurrentLeaguesDataBundle();
  2570.         var leaguesDataString = null;
  2571.  
  2572.         try {
  2573.                 leaguesDataString = leaguesDataBundle.getString(leagueID);
  2574.                 
  2575.         } catch (e) {
  2576.  
  2577.             footiefox_d_error("Failed to match league ID: " + leagueID);
  2578.             return "";
  2579.  
  2580.         }
  2581.         
  2582.         var shortCountry = "";
  2583.         try {
  2584.             shortCountry = leaguesDataString.split(":")[3];
  2585.         } catch (e) {}
  2586.         
  2587.         return shortCountry;
  2588.     },
  2589.  
  2590.  
  2591.  
  2592.     getFirstMatch: function() {
  2593.  
  2594.  
  2595.         var leagues = this.myScoreboard;
  2596.  
  2597.         var match = null;
  2598.         var status = null;
  2599.  
  2600.         var favoriteTeams = new Array();
  2601.         var teamsToFollow = this.prefNode.getCharPref("teamstofollow");
  2602.         
  2603.         //if favorite team defined, check scoreboard and pick match
  2604.         if (teamsToFollow!="") {
  2605.             teamsToFollow = teamsToFollow.split(",");
  2606.  
  2607.             var lastmatch = null;
  2608.             
  2609.             for (var u=0; u<teamsToFollow.length; u++) {
  2610.                 
  2611.                 var teamToFollow = teamsToFollow[u];
  2612.  
  2613.                 for ( var x = 0; x < leagues.length; x++ ) {
  2614.  
  2615.                     var matches = leagues[x].matches;
  2616.  
  2617.                     for ( var y = 0; y < matches.length; y++ ) {
  2618.  
  2619.                         var match = matches[y];
  2620.                         status = match.status;
  2621.  
  2622.                         var team1Id = match.team1Id;
  2623.                         var team2Id = match.team2Id;
  2624.  
  2625.                         if ((team1Id == teamToFollow || team2Id == teamToFollow) && (match.status == "scheduled" || match.status == "active" ))
  2626.                             return match;
  2627.                         
  2628.                         if ((team1Id == teamToFollow || team2Id == teamToFollow) && (match.status == "finished"))
  2629.                             lastmatch = match;
  2630.                      }
  2631.                     
  2632.                     if (lastmatch != null)
  2633.                         return lastmatch;                
  2634.                 }
  2635.             }
  2636.         }
  2637.  
  2638.  
  2639.         //select first active match
  2640.         for ( var x = 0; x < leagues.length; x++ ) {
  2641.  
  2642.             //if (leagues[x].status!="active")
  2643.             //    continue;
  2644.  
  2645.             var matches = leagues[x].matches;
  2646.  
  2647.                 for ( var y = 0; y < matches.length; y++ ) {
  2648.  
  2649.                 match = matches[y];
  2650.                 status = match.status;
  2651.                 var id = match.matchID;
  2652.  
  2653.                 if ( status == "active" ) {
  2654.                     return match;
  2655.                 }
  2656.             }
  2657.  
  2658.         }
  2659.  
  2660.  
  2661.         //if all matches finished, pick very first one which is scheduled and no placeholder
  2662.         
  2663.         for ( var x = 0; x < leagues.length; x++ ) {
  2664.  
  2665.             var matches = leagues[x].matches;
  2666.  
  2667.             for ( var y = 0; y < matches.length; y++ ) {
  2668.  
  2669.             match = matches[y];
  2670.             if (match.team1Id > 0 && match.status == "scheduled")
  2671.                 return match;
  2672.  
  2673.             }
  2674.  
  2675.         }
  2676.     
  2677.  
  2678.         return leagues[0].matches[0];
  2679.  
  2680.     },
  2681.  
  2682.     toggleRotate: function () {
  2683.  
  2684.         this.rotation=!this.rotation;
  2685.         this.prefNode.setBoolPref("rotation", this.rotation);
  2686.  
  2687.         if ( this.rotation ) {
  2688.  
  2689.             var rotationintervall = this.prefNode.getIntPref("rotationintervall");
  2690.  
  2691.             this.ffRotationTimer.initWithCallback(this.rotationTimer, rotationintervall*1000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
  2692.  
  2693.         } else {
  2694.  
  2695.                    var menuitem_rotate = document.getElementById("ff_popupmenu_rotate");
  2696.                    menuitem_rotate.setAttribute("checked", "false");
  2697.  
  2698.             this.ffRotationTimer.cancel();
  2699.         }
  2700.  
  2701.     },
  2702.  
  2703.  
  2704.     visitWebpage: function( url ) {
  2705.         
  2706.         openUILinkIn(url,"tab");
  2707.  
  2708.     },
  2709.  
  2710.  
  2711.  
  2712.     login: function() {
  2713.     
  2714.         var iconnomatches = document.getElementById("deck_minimizedlogo");
  2715.         iconnomatches.setAttribute("hidden", "true");
  2716.         
  2717.  
  2718.         this.myScoreboard = new Array();
  2719.         this.Webservice();
  2720.  
  2721.     },
  2722.  
  2723.     webserviceTimeOut: function() {
  2724.  
  2725.         if (this.whatsOnCalled) {
  2726.  
  2727.             this.switchDisplay("no_connection");
  2728.  
  2729.         }
  2730.  
  2731.     },
  2732.  
  2733.  
  2734.     Webservice: function (){
  2735.  
  2736.         try {                            
  2737.             this.callWhatsOn(false);
  2738.         
  2739.         } catch (e) {
  2740.         
  2741.             footiefox_d_error(e);
  2742.             if ( this.whatsOnCalled ) {
  2743.                 var labelnoconnection = document.getElementById("ff_notice_noconnection");
  2744.                 labelnoconnection.setAttribute("hidden", "false");
  2745.  
  2746.                 var labelnomatches = document.getElementById("ff_notice_nomatches");
  2747.                 labelnomatches.setAttribute("hidden", "true");
  2748.  
  2749.                 var labelnoleagues = document.getElementById("ff_notice_noleagues");
  2750.                 labelnoleagues.setAttribute("hidden", "true");
  2751.  
  2752.                 this.minimizeFootieFox();
  2753.             }
  2754.                     
  2755.         }
  2756.     },
  2757.     
  2758.     
  2759.     SettingsCallback: function (settingsJSON,nocache) {
  2760.     
  2761.         this.failedConnections = 0;
  2762.         
  2763.         iFootieFox.selectedMatch = null;
  2764.  
  2765.         //cache timestamp
  2766.         try {
  2767.  
  2768.             var cacheTimestamp = settingsJSON.cacheTimestamp;
  2769.             
  2770.             if (iFootieFox.prefNode.prefHasUserValue("cachetimestamp")) {
  2771.  
  2772.                 var oldTS = iFootieFox.prefNode.getCharPref("cachetimestamp");
  2773.  
  2774.                 if (oldTS != cacheTimestamp)
  2775.                     iFootieFox.emptyCache();
  2776.  
  2777.             } else
  2778.                 iFootieFox.emptyCache();
  2779.  
  2780.             iFootieFox.prefNode.setCharPref("cachetimestamp", cacheTimestamp);
  2781.  
  2782.         } catch(e) {footiefox_d_error("SettingsCallback - Cache timestamp: " + e);}
  2783.  
  2784.  
  2785.         var teamsDataBundle = null;
  2786.         var teamsDataBundleUpdated = document.getElementById("teams-data-bundle-updated");
  2787.  
  2788.         //updated teams.dat valid
  2789.         if ( teamsDataBundleUpdated.hasAttribute("src") )
  2790.             teamsDataBundle = teamsDataBundleUpdated;
  2791.         //updated teams.dat corrupt, take inbuilt teams.dat
  2792.         else
  2793.             teamsDataBundle = document.getElementById("teams-data-bundle");
  2794.  
  2795.         iFootieFox.updateInterval = settingsJSON.updateInterval;
  2796.         
  2797.  
  2798.         iFootieFox.messages = new Array();
  2799.  
  2800.         try {
  2801.             
  2802.             var messages = settingsJSON.messages;
  2803.             
  2804.             for (var i=0; i<messages.length; i++) {
  2805.  
  2806.                 var message = new Object();
  2807.                 message.url = messages[i].url;
  2808.                 message.linkurl = messages[i].linkurl;
  2809.                 message.linktext = messages[i].linktext;
  2810.                 message.time = messages[i].time;
  2811.  
  2812.                 iFootieFox.messages.push( message );
  2813.                 
  2814.             }
  2815.  
  2816.         } catch (e) {footiefox_d_error("SettingsCallback - Messages: "+e);}
  2817.  
  2818.             
  2819.         //load banner in menu
  2820.         try {
  2821.             var banners = settingsJSON.banners;
  2822.             iFootieFox.banner = null;
  2823.  
  2824.             if (banners.length > 0 ) {
  2825.  
  2826.                 var gDBTPrefService = Components.classes["@mozilla.org/preferences-service;1"]
  2827.                     .getService(Components.interfaces.nsIPrefService);
  2828.  
  2829.                 var locale = gDBTPrefService.getCharPref("general.useragent.locale");
  2830.  
  2831.                 var b = new Object();
  2832.                 for (var i=0; i<banners.length; i++) {
  2833.  
  2834.  
  2835.                     b.imageurl = banners[i].imageurl;
  2836.                     b.linkurl = banners[i].linkurl;
  2837.                     b.locale = banners[i].locale;
  2838.  
  2839.                     if (banners[i].locale == locale) {
  2840.                         iFootieFox.banner = b;
  2841.                         break;
  2842.                 }
  2843.  
  2844.                 //default
  2845.                 if (banners[i].locale == "xx-XX")
  2846.                     iFootieFox.banner = b;
  2847.  
  2848.                 }
  2849.  
  2850.                 if ( iFootieFox.banner != null ) {
  2851.  
  2852.                     var bannerImage = document.getElementById("ff_banner");
  2853.                     var bannerHbox = document.getElementById("ff_bannerhbox");
  2854.                     var bannerSep = document.getElementById("ff_bannersep");
  2855.  
  2856.                     var imageurl = iFootieFox.banner.imageurl;
  2857.  
  2858.                     if (imageurl.indexOf("http")!=0) {
  2859.  
  2860.                         if (!iFootieFox.inCache(imageurl)) {
  2861.  
  2862.                             iFootieFox.cacheFile(iFootieFox.mediaURL + iFootieFox.imagesSubdirectory + imageurl);
  2863.                             bannerImage.setAttribute("src", iFootieFox.mediaURL + iFootieFox.imagesSubdirectory + imageurl);
  2864.                         } else
  2865.                             bannerImage.setAttribute("src", "file://" + iFootieFox.tmpDir + imageurl);
  2866.  
  2867.                     } else
  2868.                         bannerImage.setAttribute("src", imageurl);
  2869.  
  2870.                     bannerHbox.setAttribute("onclick", "iFootieFox.visitWebpage('" + iFootieFox.banner.linkurl + "');");
  2871.                     bannerSep.setAttribute("hidden", "false");
  2872.                 
  2873.                 } else {
  2874.                 
  2875.                     iFootieFox.banner = null;
  2876.                     var bannerImage = document.getElementById("ff_banner");
  2877.                     var bannerHbox = document.getElementById("ff_bannerhbox");
  2878.                     var bannerSep = document.getElementById("ff_bannersep");
  2879.                     bannerImage.removeAttribute("src");
  2880.                     bannerHbox.removeAttribute("onclick");
  2881.                     bannerSep.setAttribute("hidden", "true");
  2882.                 }
  2883.  
  2884.             } else  {
  2885.  
  2886.  
  2887.                 iFootieFox.banner = null;
  2888.                 var bannerImage = document.getElementById("ff_banner");
  2889.                 var bannerHbox = document.getElementById("ff_bannerhbox");
  2890.                 var bannerSep = document.getElementById("ff_bannersep");
  2891.                 bannerImage.removeAttribute("src");
  2892.                 bannerHbox.removeAttribute("onclick");
  2893.                 bannerSep.setAttribute("hidden", "true");
  2894.  
  2895.             }
  2896.  
  2897.  
  2898.         } catch (e) {
  2899.             iFootieFox.banner = null;
  2900.             footiefox_d_error("SettingsCallback - Banner: "+e);
  2901.         }
  2902.  
  2903.  
  2904.         iFootieFox.lastMessage = 0;
  2905.  
  2906.  
  2907.         //load score_ad
  2908.         try {
  2909.             var scoreAds = settingsJSON.scoreAds;
  2910.             
  2911.             iFootieFox.scoreAds = new Array();
  2912.  
  2913.             if (scoreAds.length > 0 ) {
  2914.  
  2915.                 for (var i=0; i<scoreAds.length; i++) {
  2916.  
  2917.                     var ad = new Object();
  2918.  
  2919.                     ad.url = scoreAds[i].url;
  2920.                     ad.height = scoreAds[i].height;
  2921.                     ad.width = scoreAds[i].width;
  2922.                     ad.team_id = scoreAds[i].team;
  2923.                     ad.league_id = scoreAds[i].league;
  2924.                     ad.country_id = scoreAds[i].country;
  2925.                     ad.locale = scoreAds[i].locale;
  2926.                     ad.priority = scoreAds[i].priority;
  2927.                         
  2928.                     iFootieFox.scoreAds.push(ad);
  2929.  
  2930.                 }
  2931.  
  2932.             }
  2933.  
  2934.  
  2935.         } catch (e) {
  2936.             iFootieFox.scoreAds = null;
  2937.             footiefox_d_error("SettingsCallback - Score Ad: "+e);
  2938.         }
  2939.  
  2940.  
  2941.         iFootieFox.teamslistlasttimestamp = settingsJSON.teamsListTimestamp;
  2942.         iFootieFox.leagueslistlasttimestamp = settingsJSON.leaguesListTimestamp;
  2943.         
  2944.         //show iframe
  2945.         try {
  2946.  
  2947.             iFootieFox.iframes = new Array();
  2948.  
  2949.             for (var x=0; x<settingsJSON.iframes.length; x++) {
  2950.  
  2951.                 var iframe = new Object();
  2952.                 iframe.id = settingsJSON.iframes[x].id;
  2953.                 iframe.url = settingsJSON.iframes[x].url;
  2954.                 iframe.w = settingsJSON.iframes[x].width;
  2955.                 iframe.h = settingsJSON.iframes[x].height;
  2956.                 iframe.delay = settingsJSON.iframes[x].delay;
  2957.                 iframe.interval = settingsJSON.iframes[x].interval;
  2958.                 iframe.datetime = settingsJSON.iframes[x].show_on;
  2959.                 iframe.locale = settingsJSON.iframes[x].locale;
  2960.                 
  2961.                 iFootieFox.iframes.push(iframe);
  2962.  
  2963.             }
  2964.  
  2965.  
  2966.             iFootieFox.processIFrames();
  2967.  
  2968.  
  2969.         } catch (e) {
  2970.             footiefox_d_error("SettingsCallback - Iframes: "+e);
  2971.         }
  2972.         
  2973.         
  2974.         try {
  2975.         
  2976.             iFootieFox.availableHosts = settingsJSON.hosts.split(",");
  2977.             
  2978.             for (var i=0; i<iFootieFox.availableHosts.length; i++) {
  2979.                 iFootieFox.availableHosts[i] = "http://"+iFootieFox.availableHosts[i]+"/";
  2980.             }
  2981.             
  2982.             var currentHost = iFootieFox.prefNode.getCharPref("host");
  2983.             if (currentHost == "") {
  2984.             
  2985.                 var index = Math.random();
  2986.                 
  2987.                 index *= iFootieFox.availableHosts.length;
  2988.                 index = Math.ceil(index);
  2989.  
  2990.                 iFootieFox.apiURL = iFootieFox.availableHosts[index-1];
  2991.                 iFootieFox.prefNode.setCharPref("host",iFootieFox.apiURL);
  2992.                 
  2993.             }
  2994.         
  2995.         
  2996.         } catch (e) {
  2997.             footiefox_d_error("Hosts: "+e);
  2998.         }
  2999.        
  3000.        
  3001.         iFootieFox.requestAllLeagueBases(nocache);
  3002.     
  3003.     },
  3004.     
  3005.     LeagueBaseCallback: function (leagueJSON) {
  3006.         
  3007.         this.failedConnections = 0;
  3008.     
  3009.         //footiefox_d_message("LeagueBaseCallback: "+ leagueJSON.leagueID);
  3010.         var countriesDataBundle = document.getElementById("countries-data-bundle");
  3011.  
  3012.         var teamsDataBundle = null;
  3013.         var teamsDataBundleUpdated = document.getElementById("teams-data-bundle-updated");
  3014.  
  3015.         //updated teams.dat valid
  3016.         if ( teamsDataBundleUpdated.hasAttribute("src") )
  3017.             teamsDataBundle = teamsDataBundleUpdated;
  3018.         //updated teams.dat corrupt, take inbuilt teams.dat
  3019.         else
  3020.             teamsDataBundle = document.getElementById("teams-data-bundle");
  3021.  
  3022.  
  3023.         var league = new Object();
  3024.  
  3025.         league.leagueID = leagueJSON.leagueID;
  3026.         
  3027.         // is this league a tournament?
  3028.         if (typeof(leagueJSON.is_tournament) != 'undefined')
  3029.             league.is_tournament = leagueJSON.is_tournament;
  3030.         else
  3031.             league.is_tournament = false;
  3032.         
  3033.         league.timestamp = leagueJSON.timestamp;
  3034.         league.matches = new Array();
  3035.  
  3036.         var currentMatches = null;
  3037.  
  3038.         try {
  3039.                 currentMatches = leagueJSON.matches;
  3040.         } catch (e) {
  3041.                 
  3042.                 footiefox_d_error(e);
  3043.                 
  3044.         }
  3045.         
  3046.         
  3047.         if (currentMatches.length == 0) {
  3048.             
  3049.             iFootieFox.registerLeagueBaseCallback();            
  3050.             return;
  3051.         }
  3052.         
  3053.         for (var y=0; y<currentMatches.length; y++) {
  3054.             
  3055.             var resMatch = currentMatches[y];
  3056.             
  3057.             var match = new Object();
  3058.  
  3059.             match.matchID = resMatch.matchID;
  3060.             
  3061.             var date = iFootieFox.parseDate( resMatch.startTime );
  3062.             
  3063.             match.startTime = date.getTime();
  3064.  
  3065.             match.team1Id = resMatch.team1Id;
  3066.             match.team2Id = resMatch.team2Id;
  3067.             
  3068.             match.phase = null;
  3069.             if (typeof(resMatch.phase) != 'undefined') {
  3070.                 
  3071.                 match.phase = this.getMatchPhase(resMatch.phase);
  3072.             }
  3073.             
  3074.             try {
  3075.             
  3076.                 match.team1Title = countriesDataBundle.getString(resMatch.team1Id);
  3077.             
  3078.             } catch (e) {
  3079.                     
  3080.                     try {
  3081.                         
  3082.                         var value = teamsDataBundle.getString(resMatch.team1Id);
  3083.                         match.team1Title = value.split(":")[1];
  3084.                         
  3085.                     } catch (e) {
  3086.                         match.team1Title = "<" + iFootieFox.dictionary.getString("ff.notice.notitle") + ">";
  3087.  
  3088.                 }
  3089.             }
  3090.  
  3091.             try {
  3092.             
  3093.                 match.team2Title = countriesDataBundle.getString(resMatch.team2Id);
  3094.             
  3095.             } catch (e) {
  3096.                     
  3097.                     try {
  3098.                         var value = teamsDataBundle.getString(resMatch.team2Id);
  3099.                         match.team2Title = value.split(":")[1];
  3100.                         
  3101.                     } catch (e) {
  3102.                         match.team2Title = "<" + iFootieFox.dictionary.getString("ff.notice.notitle") + ">";
  3103.  
  3104.                 }
  3105.             }
  3106.             
  3107.             if (typeof(resMatch.tournament_group) != 'undefined')
  3108.                 match.tournament_group = resMatch.tournament_group;
  3109.             
  3110.  
  3111.             match.team1Score = resMatch.team1Score;
  3112.             match.team2Score = resMatch.team2Score;
  3113.             match.status = resMatch.status;
  3114.             match.url = resMatch.url;
  3115.  
  3116.             try {
  3117.                 match.url2 = resMatch.url2;
  3118.             } catch (e) {}
  3119.  
  3120.             league.matches.push( match );
  3121.  
  3122.         }
  3123.         
  3124.  
  3125.         this.myScoreboard.push( league );
  3126.         this.registerLeagueBaseCallback();
  3127.  
  3128.         
  3129.     },
  3130.     
  3131.     registerLeagueBaseCallback: function() {
  3132.     
  3133.             leagueBaseRefreshed += 1;
  3134.             
  3135.             if (leagueBaseRefreshed >= this.myLeagues.length) {
  3136.             
  3137.                 iFootieFox.whatsOnCalled = false;
  3138.                 
  3139.                 //update login timestamp
  3140.                 var now = new Date();
  3141.                 var nowTS = now.getTime();
  3142.                 iFootieFox.prefNode.setCharPref("logintimestamp", nowTS);
  3143.                 
  3144.                 iFootieFox.cacheImages();
  3145.                 iFootieFox.serializeData();
  3146.                 iFootieFox.dataRefreshed();
  3147.             }
  3148.  
  3149.     },
  3150.     
  3151.     registerLeagueUpdateCallback: function() {
  3152.     
  3153.         leagueUpdateRefreshed +=1;
  3154.         
  3155.         if (leagueUpdateRefreshed >= iFootieFox.myScoreboard.length) {
  3156.             
  3157.             this.serializeData();
  3158.             this.dataRefreshed();
  3159.         }
  3160.     
  3161.     },
  3162.     
  3163.     registerFailedConnection: function(severity) {
  3164.     
  3165.         this.failedConnections += severity;
  3166.         
  3167.         if (this.failedConnections >= 5) {
  3168.             
  3169.             //reset failure count
  3170.             this.failedConnections = 0;
  3171.             
  3172.             if (this.availableHosts.length > 0) {
  3173.                 
  3174.                 
  3175.                 //remove host from list
  3176.                 for (var i=0; i<this.availableHosts.length; i++) {
  3177.                     
  3178.                     if (this.availableHosts[i] == this.apiURL) {
  3179.                         this.availableHosts.splice(i,1);
  3180.                         
  3181.                         break;
  3182.                     }
  3183.                     
  3184.                 }
  3185.                 
  3186.                 var index = Math.random();
  3187.                 
  3188.                 index *= iFootieFox.availableHosts.length;
  3189.                 index = Math.ceil(index);
  3190.  
  3191.                 this.apiURL = iFootieFox.availableHosts[index-1];
  3192.                 iFootieFox.prefNode.setCharPref("host",this.apiURL);
  3193.                 
  3194.                 footiefox_d_error("Connection failed, new server: "+ this.apiURL);
  3195.                 
  3196.                 //retry with new host
  3197.                 setTimeout("iFootieFox.callWhatsOn(false)", 50);
  3198.                 
  3199.                 
  3200.             } else {
  3201.             
  3202.                 this.apiURL = this.first_apiURL;
  3203.             
  3204.                 //failed desperately
  3205.                 this.webserviceTimeOut();
  3206.                 
  3207.             }
  3208.            
  3209.         }
  3210.     
  3211.     },
  3212.     
  3213.     LeagueUpdateCallback: function (updateJSON) {
  3214.  
  3215.         footiefox_di_message("LeagueUpdateCallback");
  3216.         
  3217.         this.failedConnections = 0;
  3218.         
  3219.         var matchDiffs = new Array();
  3220.  
  3221.         for (var i=0; i<updateJSON.length; i++) {
  3222.  
  3223.             var matchDiff = new Object();
  3224.             
  3225.             matchDiff.matchId = updateJSON[i].matchID;
  3226.  
  3227.             var match = iFootieFox.getMatch( matchDiff.matchId );
  3228.             matchDiff.team1Score = updateJSON[i].team1Score;
  3229.             matchDiff.team2Score = updateJSON[i].team2Score;
  3230.             
  3231.             matchDiff.phase = null;
  3232.             
  3233.             if (typeof(updateJSON[i].phase) != 'undefined') {
  3234.                 matchDiff.phase = this.getMatchPhase(updateJSON[i].phase);
  3235.             }
  3236.  
  3237.             if (matchDiff.team1Score > match.team1Score) {
  3238.                 matchDiff.teamId = match.team1Id;
  3239.             } else if (matchDiff.team2Score > match.team2Score) {
  3240.                     matchDiff.teamId = match.team2Id;
  3241.             } else
  3242.                 matchDiff.teamId = null;
  3243.  
  3244.  
  3245.             matchDiff.status = updateJSON[i].status;
  3246.  
  3247.             matchDiffs.push(matchDiff);
  3248.         }
  3249.         
  3250.         this.registerLeagueUpdateCallback();
  3251.  
  3252.         iFootieFox.updateData(matchDiffs, false);
  3253.  
  3254.         
  3255.  
  3256.     },
  3257.     
  3258.     dataRefreshed: function () {
  3259.  
  3260.         //d("dataRefreshed");
  3261.         
  3262.  
  3263.         var deckProgressmeter = document.getElementById("deck_progressmeter");
  3264.         deckProgressmeter.setAttribute("hidden", "true");
  3265.  
  3266.         if ( this.myScoreboard.length > 0 ) {
  3267.  
  3268.             //build popup menu
  3269.             this.buildMenu();
  3270.  
  3271.             this.synchronizeTeamsList();
  3272.             
  3273.             this.synchronizeLeaguesList();
  3274.             
  3275.             this.displayMatch( this.selectedMatch );
  3276.             
  3277.  
  3278.             this.ffTimer.initWithCallback(this.updateLeagues, this.updateInterval, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
  3279.         } else {
  3280.                 
  3281.             //no leagues selected at all
  3282.             if (this.myLeagues.length == 0) {
  3283.  
  3284.                 this.switchDisplay("no_leagues");
  3285.                 
  3286.             
  3287.             } else if (failedLeagues == this.myLeagues.length) { 
  3288.             
  3289.                 this.switchDisplay("no_connection");
  3290.                 
  3291.             //none of the selected leagues are active
  3292.             } else {
  3293.             
  3294.                 this.switchDisplay("no_matches");
  3295.  
  3296.             }
  3297.  
  3298.          }
  3299.  
  3300.  
  3301.         if ( this.messages.length > 0 ) {
  3302.             this.processMessages();
  3303.         }
  3304.         
  3305.  
  3306.     },
  3307.  
  3308.  
  3309.     parseDate: function ( datestring ) {
  3310.  
  3311.             if (datestring == null)
  3312.                 return null;
  3313.  
  3314.         
  3315.         //var time = datestring.split("T")[1];
  3316.         //var date = datestring.split("T")[0];
  3317.         
  3318.         var time = datestring.split(" ")[1];
  3319.         var date = datestring.split(" ")[0];
  3320.  
  3321.         var startHrs = parseInt(time.split(":")[0], 10);
  3322.         var startMins = parseInt(time.split(":")[1], 10);
  3323.         var startDay = date.split("-")[2];
  3324.         var startMonth = parseInt(date.split("-")[1], 10);
  3325.         var startYear = parseInt(date.split("-")[0], 10);
  3326.  
  3327.             var utcdate = new Date();
  3328.  
  3329.         utcdate.setUTCFullYear( startYear, startMonth -1, startDay );
  3330.             utcdate.setUTCHours( startHrs, startMins, 0  );
  3331.  
  3332.  
  3333.         return utcdate;
  3334.  
  3335.     },
  3336.  
  3337.     checkET: function () {
  3338.     
  3339.         
  3340.         var ET = 0;
  3341.         
  3342.         try {
  3343.             
  3344.             ET = parseInt(this.prefNode.getCharPref("ET"));
  3345.         
  3346.         } catch (e) { 
  3347.  
  3348.             this.prefNode.setCharPref("ET", 0);
  3349.             
  3350.         }
  3351.         
  3352.         var now = new Date(); 
  3353.         var nowUTC = now.getTime();
  3354.         
  3355.         if ((nowUTC-ET > 24*60*60*1000) && (this.ETchecking == false)) {
  3356.             
  3357.             
  3358.             this.ETchecking = true;
  3359.             
  3360.             var req = new XMLHttpRequest();
  3361.             var locale = null;
  3362.             try {
  3363.                 locale = this.prefNode.getCharPref("locale");
  3364.             } catch (e) {}
  3365.             
  3366.             
  3367.             
  3368.             var url = this.redirectURL+"ping?client_id="+this.getSerial()+"&locale="+locale;
  3369.                     
  3370.             
  3371.             req.open('GET', url, true);
  3372.             req.onreadystatechange = function (aEvt) {
  3373.               if (req.readyState == 4) {
  3374.                  if(req.status == 200) {
  3375.                     
  3376.                     iFootieFox.prefNode.setCharPref("ET", nowUTC);
  3377.                     iFootieFox.ETchecking = false;
  3378.                     
  3379.                   
  3380.                  } else {
  3381.                   iFootieFox.ETchecking = false;
  3382.                 }
  3383.               }
  3384.             };
  3385.             req.send(null); 
  3386.             
  3387.             
  3388.         }
  3389.         
  3390.     
  3391.     },
  3392.  
  3393.     callWhatsOn: function (nocache){
  3394.  
  3395.         footiefox_d_message("callWhatsOn");
  3396.         
  3397.         this.checkFirstExtension();
  3398.         
  3399.         if ( !this.firstExtension ) {
  3400.  
  3401.             //false if serialized data outdated
  3402.             if ( this.parseSerializedData() ) {
  3403.                 this.dataRefreshed();
  3404.                 return;
  3405.             }
  3406.         
  3407.         }
  3408.         
  3409.         this.switchDisplay("progress");
  3410.         window.setTimeout("iFootieFox.webserviceTimeOut()", 15000);
  3411.         
  3412.         this.checkET();
  3413.         this.updateMyLeagues();
  3414.         this.updateMyTeams();
  3415.         
  3416.         this.requestSettings(nocache);
  3417.         
  3418.         
  3419.     },
  3420.     
  3421.     requestAllLeagueBases: function(nocache) {
  3422.         
  3423.         if  ( this.myLeagues.length > 0 || this.optionsClosed) {
  3424.         
  3425.             this.optionsClosed = false;
  3426.  
  3427.             this.checkFirstExtension();
  3428.  
  3429.             if ( !this.firstExtension ) {
  3430.  
  3431.                 //false if serialized data outdated
  3432.                 if ( this.parseSerializedData() ) {
  3433.                     this.dataRefreshed();
  3434.                     return;
  3435.                 }
  3436.             }
  3437.  
  3438.  
  3439.             this.whatsOnCalled = true;
  3440.             
  3441.             iFootieFox.myScoreboard = new Array();
  3442.             leagueBaseRefreshed = 0;
  3443.             failedLeagues = 0;
  3444.             
  3445.             
  3446.             
  3447.             if (this.myLeagues.length == 0)
  3448.                 this.switchDisplay("no_leagues");
  3449.             
  3450.             for (var i=0; i<this.myLeagues.length; i++) {
  3451.                 
  3452.                 try {
  3453.                 
  3454.                     this.requestLeagueBase(this.myLeagues[i], nocache);
  3455.                 
  3456.                 } catch (e) {
  3457.                     footiefox_d_error("requestLeagueBase failed for league "+this.myLeagues[i] +": "+e);
  3458.                     leagueBaseRefreshed +=1;
  3459.                     //footiefox_d_error("catch request"+leagueBaseRefreshed);
  3460.                     if (leagueBaseRefreshed >= this.myLeagues.length) {
  3461.                         this.dataRefreshed();
  3462.                     }
  3463.                 }
  3464.             }
  3465.                         
  3466.           } else    {
  3467.         
  3468.             this.switchDisplay("no_leagues");
  3469.           }
  3470.     
  3471.     },
  3472.     
  3473.     switchDisplay: function(status) {
  3474.     
  3475.         var labelnoleagues = document.getElementById("ff_notice_noleagues");
  3476.         var labelnomatches = document.getElementById("ff_notice_nomatches");
  3477.         var labelnoconnection = document.getElementById("ff_notice_noconnection");
  3478.         var deck_team1 = document.getElementById("deck_team1");
  3479.         var deck_team2 = document.getElementById("deck_team2");
  3480.         var deck_score = document.getElementById("deck_score");
  3481.         var deckProgressmeter = document.getElementById("deck_progressmeter");
  3482.         var iconnomatches = document.getElementById("deck_minimizedlogo");
  3483.         
  3484.         switch (status) {
  3485.         
  3486.             case "no_leagues":
  3487.             
  3488.                 labelnoleagues.setAttribute("hidden", "false");
  3489.                 labelnomatches.setAttribute("hidden", "true");
  3490.                 labelnoconnection.setAttribute("hidden", "true");
  3491.                 
  3492.                 this.minimizeFootieFox();
  3493.                 
  3494.                 break;
  3495.                 
  3496.             case "no_matches":
  3497.             
  3498.                 labelnoleagues.setAttribute("hidden", "true");
  3499.                 labelnomatches.setAttribute("hidden", "false");
  3500.                 labelnoconnection.setAttribute("hidden", "true");
  3501.                 
  3502.                 this.minimizeFootieFox();
  3503.                 
  3504.                 break;
  3505.                 
  3506.             case "progress":
  3507.                 
  3508.                 deck_team1.setAttribute ("hidden", "true");
  3509.                 deck_team2.setAttribute ("hidden", "true");
  3510.                 deck_score.setAttribute ("hidden", "true");
  3511.                 deckProgressmeter.setAttribute("hidden", "false");
  3512.                 iconnomatches.setAttribute("hidden", "true");
  3513.                 
  3514.                 break;
  3515.                 
  3516.             case "match":
  3517.             
  3518.                 deck_team1.setAttribute ("hidden", "false");
  3519.                 deck_team2.setAttribute ("hidden", "false");
  3520.                 deck_score.setAttribute ("hidden", "false");
  3521.                 labelnomatches.setAttribute("hidden", "true");
  3522.                 labelnoconnection.setAttribute("hidden", "true");
  3523.                 labelnoleagues.setAttribute("hidden", "true");
  3524.                 iconnomatches.setAttribute("hidden", "true");
  3525.                 
  3526.                 break;
  3527.                 
  3528.             case "minimized":
  3529.             
  3530.                 deck_team1.setAttribute ("hidden", "true");
  3531.                 deck_team2.setAttribute ("hidden", "true");
  3532.                 deck_score.setAttribute ("hidden", "true");
  3533.                 deckProgressmeter.setAttribute("hidden", "true");
  3534.                 iconnomatches.setAttribute("hidden", "false");
  3535.                 
  3536.                 break;
  3537.                 
  3538.             case "no_connection":
  3539.                 
  3540.                 labelnoconnection.setAttribute("hidden", "false");
  3541.                 labelnomatches.setAttribute("hidden", "true");
  3542.                 labelnoleagues.setAttribute("hidden", "true");
  3543.  
  3544.                 this.minimizeFootieFox();
  3545.                 
  3546.                 break;
  3547.         }
  3548.     
  3549.     },
  3550.     
  3551.     
  3552.     requestSettings: function(nocache) {
  3553.         
  3554.         footiefox_d_message("requestSettings");        
  3555.         
  3556.         var request = new XMLHttpRequest();
  3557.         request.onreadystatechange = function() {
  3558.             
  3559.             try {
  3560.                 
  3561.                 if (request.readyState == 4 ) {
  3562.                     
  3563.                     if ( request.status == 200) {
  3564.  
  3565.                         var jsonObject =  eval('(' + request.responseText + ')');
  3566.                         
  3567.                         iFootieFox.SettingsCallback(jsonObject,nocache);
  3568.                         
  3569.                     }
  3570.                     
  3571.                     if ( request.status == 404 || request.status == 0 || request.status == 408 || request.status == 500 || request.status == 503 || request.status == 504 ) {
  3572.                         
  3573.                         footiefox_d_error("requestSettings failed: " + request.status);
  3574.                         iFootieFox.registerFailedConnection(5);
  3575.                         
  3576.                     }
  3577.                     
  3578.                 }
  3579.                 
  3580.             } catch (e) {
  3581.                 
  3582.                 footiefox_d_message("requestSettings: "+ e);
  3583.                 iFootieFox.registerFailedConnection(5);
  3584.                 
  3585.             }
  3586.         }
  3587.         
  3588.     
  3589.         request.open("GET", this.apiURL + "/settings.json");
  3590.         
  3591.         request.send(null);
  3592.     
  3593.     
  3594.     
  3595.     },
  3596.     
  3597.     requestLeagueBase: function(id, nocache) {
  3598.         //footiefox_d_message("requestLeagueBase: "+id);        
  3599.         
  3600.         var request = new XMLHttpRequest();
  3601.         request.onreadystatechange = function() {
  3602.             
  3603.             try {
  3604.                 
  3605.                 if (request.readyState == 4 ) {
  3606.                 
  3607.                     if ( request.status == 200) {
  3608.                         
  3609.                         var jsonObject =  eval('(' + request.responseText + ')');
  3610.                         
  3611.                         iFootieFox.LeagueBaseCallback(jsonObject);
  3612.                         
  3613.                     }
  3614.                     
  3615.                     
  3616.                     if ( request.status == 404 || request.status == 0 || request.status == 408 || request.status == 500 || request.status == 503 || request.status == 504 ) {
  3617.                         
  3618.                         failedLeagues +=1; 
  3619.                         footiefox_d_error("league base request for league " + id +" failed permanently");                        
  3620.                         
  3621.                         footiefox_d_error("requestLeagueBase failed: " + request.status);
  3622.                         iFootieFox.registerFailedConnection(1);
  3623.                         
  3624.                     }
  3625.                     
  3626.                 }
  3627.                 
  3628.             } catch (e) {
  3629.             
  3630.                 //FootieFox: requestLeagueBase ...: [Exception... "Component returned failure code: 0x80040111 
  3631.                 //(NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  
  3632.                 //location: "JS frame :: chrome://footiefox/content/footiefox.js :: anonymous :: line 4116"  data: no]
  3633.  
  3634.                 iFootieFox.registerFailedConnection(1);
  3635.                 
  3636.                 //request failed, retry
  3637.                 footiefox_d_error("requestLeagueBase ...: "+e);
  3638.                 window.setTimeout("iFootieFox.requestLeagueBase("+id+")", 10000);
  3639.             
  3640.             }
  3641.         }
  3642.         
  3643.         
  3644.         request.open("GET", this.apiURL + "leagues/"+id+"/base.json");
  3645.         
  3646.         //
  3647.         if (nocache) {
  3648.             request.setRequestHeader("Cache-Control", "no-cache"); 
  3649.             request.setRequestHeader("Pragma", "no-cache"); 
  3650.             request.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT"); 
  3651.         }
  3652.         
  3653.         request.send(null);
  3654.     
  3655.     },
  3656.     
  3657.     requestLeagueUpdate: function(id) {
  3658.         
  3659.         //footiefox_d_message("requestLeagueUpdate: "+id);        
  3660.         
  3661.         var request = new XMLHttpRequest();
  3662.         request.onreadystatechange = function() {
  3663.             
  3664.             try {
  3665.                 
  3666.                 if (request.readyState == 4) {
  3667.  
  3668.                     if (request.status == 200) {
  3669.                         
  3670.                         var jsonObject =  eval('(' + request.responseText + ')');
  3671.                         
  3672.                         iFootieFox.LeagueUpdateCallback(jsonObject);
  3673.                         
  3674.                     }
  3675.                     
  3676.                     if ( request.status == 404 || request.status == 0 || request.status == 408 || request.status == 500 || request.status == 503 || request.status == 504 ) {
  3677.                             
  3678.                         failedLeagues +=1; 
  3679.                         footiefox_d_error("league update request for league " + id +" failed permanently");                        
  3680.                         
  3681.                         footiefox_d_error("requestLeagueUpdate failed: " + request.status);
  3682.                         iFootieFox.registerFailedConnection(1);
  3683.                             
  3684.                     }
  3685.                 }
  3686.                 
  3687.             } catch (e) {
  3688.             
  3689.                 footiefox_d_error("request for league "+ id + " failed:"+e);
  3690.                 iFootieFox.registerLeagueUpdateCallback();
  3691.                 iFootieFox.registerFailedConnection(1);
  3692.                 //request failed
  3693.                 //alert("request for league "+ id + " failed:"+e);
  3694.                 
  3695.             
  3696.             }
  3697.         }
  3698.         
  3699.         request.open("GET", this.apiURL + "leagues/"+id+"/update.json");
  3700.         
  3701.         
  3702.         request.send(null);
  3703.     
  3704.     },
  3705.     
  3706.  
  3707.     processMessages: function() {
  3708.  
  3709.  
  3710.         var messages = this.messages;
  3711.  
  3712.         this.messageTimer = new Array();
  3713.  
  3714.         for ( var x = 0; x < messages.length; x++ ) {
  3715.             
  3716.             var message = messages[x];
  3717.  
  3718.             var url = message.url;
  3719.             var fileName = url.substring(url.lastIndexOf('/')+1, url.length);
  3720.  
  3721.             if (!this.inCache(fileName))
  3722.                 this.cacheFile(url, false);
  3723.  
  3724.             var datetime = message.time;
  3725.             var date = this.parseDate( datetime );
  3726.  
  3727.             var waitingTime = this.messureTime( date );
  3728.             
  3729.             var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  3730.  
  3731.             var showMessage = {
  3732.  
  3733.                     notify: function() {
  3734.  
  3735.                         iFootieFox.checkFirstExtension();
  3736.  
  3737.                     if ( iFootieFox.firstExtension )
  3738.                         iFootieFox.messageAlert();
  3739.                 }
  3740.             };
  3741.  
  3742.             timer.initWithCallback(showMessage, waitingTime*1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
  3743.  
  3744.             this.messageTimer.push (timer);
  3745.  
  3746.         }
  3747.     },
  3748.  
  3749.  
  3750.         processIFrames: function() {
  3751.  
  3752.             var iframes = this.iframes;
  3753.  
  3754.             if (this.iframeTimer.length>0 )  {
  3755.  
  3756.                 for (var z=0; z<this.iframeTimer.length; z++)
  3757.                         this.iframeTimer[z].cancel();
  3758.  
  3759.             }
  3760.  
  3761.             var locale = this.prefNode.getCharPref("locale");
  3762.             
  3763.             this.iframeTimer = new Array();
  3764.  
  3765.             for ( var x = 0; x < iframes.length; x++ ) {
  3766.  
  3767.                 var iframe = iframes[x];
  3768.  
  3769.                 //skip if locale different
  3770.                 if ( !(iframe.locale == locale || iframe.locale == "xx-XX") )
  3771.                     continue;
  3772.  
  3773.                 var waitingTime = 0;
  3774.                 
  3775.  
  3776.                 if ( iframe.datetime!=null && iframe.datetime!="") {
  3777.  
  3778.                     var date = this.parseDate( iframe.datetime );
  3779.                     waitingTime = this.messureTime( date );
  3780.                     
  3781.                 } else {
  3782.                 
  3783.                     waitingTime = iframe.delay;
  3784.                     
  3785.                 }
  3786.                 
  3787.                 
  3788.                 
  3789.                 var firstTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  3790.                 var repeatingTimer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
  3791.  
  3792.                 var showIFrame = {
  3793.  
  3794.                     id: 0,
  3795.                     url: "",
  3796.                     w: 0,
  3797.                     h:0,
  3798.  
  3799.                     init: function(id, url, w, h) {
  3800.                             this.id = id;
  3801.                             this.url = url;
  3802.                             this.w = w;
  3803.                             this.h = h;
  3804.  
  3805.                     },
  3806.  
  3807.                     notify: function() {
  3808.  
  3809.                         iFootieFox.checkFirstExtension();
  3810.  
  3811.                         if ( iFootieFox.firstExtension )
  3812.                             iFootieFox.displayIFrame(this.id, this.url, this.w, this.h);
  3813.                         }
  3814.                 };
  3815.                 
  3816.                 showIFrame.init(iframe.id, iframe.url, iframe.w, iframe.h);
  3817.                 
  3818.                 if (waitingTime > 0) {
  3819.                     firstTimer.initWithCallback(showIFrame, waitingTime*1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
  3820.  
  3821.                 } 
  3822.                 /*else {
  3823.                     firstTimer.initWithCallback(showIFrame, iframe.delay*1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
  3824.                     repeatingTimer.initWithCallback(showIFrame, iframe.interval*1000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
  3825.  
  3826.                     this.iframeTimer.push (repeatingTimer);
  3827.                 }*/
  3828.  
  3829.  
  3830.                 this.iframeTimer.push (firstTimer);
  3831.  
  3832.             }
  3833.  
  3834.     },
  3835.  
  3836.     emptyCache: function () {
  3837.  
  3838.         //tmp dir not set
  3839.         if (!this.tmpDir || this.tmpDir == "")
  3840.             return;
  3841.  
  3842.         //tmpDir contains name of cache folder
  3843.             if (this.tmpDir.search(this.cacheFolder)> -1 ) {
  3844.  
  3845.             var directory = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  3846.             directory.initWithPath(this.tmpDir);
  3847.             try {
  3848.                 directory.remove(true);
  3849.             } catch (e) { footiefox_d_error(e);}
  3850.  
  3851.             //reset timestamps
  3852.             this.prefNode.setCharPref("leagueslisttimestamp", "");
  3853.             this.prefNode.setCharPref("teamslisttimestamp", "");
  3854.             }
  3855.     },
  3856.  
  3857.     messureTime: function ( date ) {
  3858.  
  3859.             var now = new Date();
  3860.  
  3861.         var waitingTime = date.getTime() - now.getTime();
  3862.  
  3863.         //returns seconds
  3864.         return Math.round(waitingTime/1000);
  3865.  
  3866.     },
  3867.  
  3868.     compareMatches: function (a, b) {
  3869.  
  3870.         var aStartTime = a.startTime;
  3871.  
  3872.                 var bStartTime = b.startTime;
  3873.  
  3874.  
  3875.  
  3876.             if (aStartTime < bStartTime)
  3877.                   return -1;
  3878.            if (aStartTime > bStartTime)
  3879.                   return 1;
  3880.  
  3881.            return 0;
  3882.     },
  3883.  
  3884.     sortMatchesByTime: function () {
  3885.         //d("sortMatchesByTime");
  3886.  
  3887.         for ( var x = 0; x < this.myScoreboard.length; x++ ) {
  3888.  
  3889.  
  3890.             this.myScoreboard[x].matches.sort(this.compareMatches);
  3891.  
  3892.         }
  3893.  
  3894.  
  3895.     },
  3896.  
  3897.  
  3898.  
  3899.     synchronizeTeamsList: function() {
  3900.  
  3901.         //d("synchronizeTeamsList");
  3902.  
  3903.         if (!this.inCache("teams.dat") || this.teamslistlasttimestamp != this.prefNode.getCharPref("teamslisttimestamp")) {
  3904.             this.cacheFile (this.apiURL + "teams.dat", true);
  3905.             this.prefNode.setCharPref("teamslisttimestamp", this.teamslistlasttimestamp);
  3906.  
  3907.         }
  3908.     },
  3909.  
  3910.     synchronizeLeaguesList: function() {
  3911.  
  3912.         //d("synchronizeLeaguesList");
  3913.  
  3914.         if (!this.inCache("leagues.dat") || this.leagueslistlasttimestamp != this.prefNode.getCharPref("leagueslisttimestamp")) {
  3915.             this.cacheFile (this.apiURL + "leagues.dat", true);
  3916.             this.prefNode.setCharPref("leagueslisttimestamp", this.leagueslistlasttimestamp);
  3917.  
  3918.         }
  3919.     },
  3920.  
  3921.  
  3922.     cacheImages: function() {
  3923.  
  3924.         //d("cacheImages");
  3925.  
  3926.         var leagues = this.myScoreboard;
  3927.  
  3928.             //small logos first
  3929.         for ( var x = 0; x < leagues.length; x++ ) {
  3930.  
  3931.             var matches = leagues[x].matches;
  3932.  
  3933.             for ( var y = 0; y < matches.length; y++ ) {
  3934.  
  3935.                 var match = matches[y];
  3936.  
  3937.                 if (match.team1Id != -1) {
  3938.                     this.cacheFile (this.mediaURL + this.imagesSubdirectory + match.team1Id + ".png", false);
  3939.                 }
  3940.                 if (match.team2Id != -1) {
  3941.                     this.cacheFile (this.mediaURL + this.imagesSubdirectory + match.team2Id + ".png", false);
  3942.                 }
  3943.             }
  3944.  
  3945.         }
  3946.  
  3947.         //cache menu header
  3948.         this.cacheFile (this.mediaURL + this.imagesSubdirectory + "contextmenuheader.png", false);
  3949.  
  3950.             //now the big ones
  3951.         for ( var x = 0; x < leagues.length; x++ ) {
  3952.  
  3953.             var matches = leagues[x].matches;
  3954.  
  3955.             for ( var y = 0; y < matches.length; y++ ) {
  3956.  
  3957.                 var match = matches[y];
  3958.                 if (match.team1Id != -1) {
  3959.                     this.cacheFile (this.mediaURL + this.imagesSubdirectory + match.team1Id + "big.png", false);
  3960.                 }
  3961.                 if (match.team2Id != -1) {
  3962.                     this.cacheFile (this.mediaURL + this.imagesSubdirectory + match.team2Id + "big.png", false);
  3963.                 }
  3964.             }
  3965.  
  3966.         }
  3967.  
  3968.  
  3969.     },
  3970.  
  3971.     
  3972.     minimizeFootieFox: function() {
  3973.  
  3974.         this.switchDisplay("minimized");
  3975.         
  3976.         var deck_footiefox_arrow = document.getElementById("deck_footiefox_arrow");
  3977.         
  3978.         var footiefox_statusbarpanel = document.getElementById("footiefox_statusbarpanel");
  3979.         
  3980.         if (this.prefNode.prefHasUserValue("discretemode"))
  3981.             if (!this.prefNode.getBoolPref("discretemode")) {
  3982.  
  3983.                 footiefox_statusbarpanel.setAttribute ("collapsed", "false");
  3984.                 
  3985.  
  3986.             } else {
  3987.                 
  3988.                 footiefox_statusbarpanel.setAttribute ("collapsed", "true");
  3989.                 
  3990.                 
  3991.             }
  3992.  
  3993.         var mainPopupSet = document.getElementById("menupopup_mainmenupopup");
  3994.  
  3995.  
  3996.         this.removeMenu();
  3997.  
  3998.  
  3999.  
  4000.  
  4001.     },
  4002.  
  4003.     updateRotationTimer: function() {
  4004.  
  4005.         var rotationintervall = this.prefNode.getIntPref("rotationintervall");
  4006.         this.ffRotationTimer.initWithCallback(this.rotationTimer, rotationintervall*1000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
  4007.  
  4008.     },
  4009.  
  4010.  
  4011.     openOptions: function(tab) {
  4012.     
  4013.         openDialog("chrome://footiefox/content/options.xul", "options", "chrome,dialog,centerscreen", tab);
  4014.  
  4015.  
  4016.     },
  4017.  
  4018.  
  4019.     openAbout: function() {
  4020.  
  4021.  
  4022.         openDialog("chrome://footiefox/content/about.xul", "about", "chrome");
  4023.  
  4024.     },
  4025.  
  4026.     openMessageURL: function() {
  4027.  
  4028.         this.visitWebpage(this.messages[ this.lastMessage - 1 ].linkurl);
  4029.  
  4030.     },
  4031.     
  4032.     getSerial: function() {
  4033.         
  4034.         var serial = null;
  4035.             try {
  4036.                 if (this.prefNode.getBoolPref("serial.agreed")) {
  4037.                 
  4038.                     if (this.prefNode.prefHasUserValue("serial.number")) {
  4039.                      serial = this.prefNode.getCharPref("serial.number");
  4040.                     }
  4041.                 
  4042.                 
  4043.                 }
  4044.             } catch (e) {footiefox_d_error(e)}
  4045.             
  4046.             return serial;
  4047.         
  4048.     },
  4049.     
  4050.     partnerBannerClicked: function(event, adspaceid,partnerid) {
  4051.         
  4052.         if (event == null || event.button == 0 ) {
  4053.         
  4054.             this.visitWebpage(this.redirectURL+"redirect/"+partnerid+"/"+adspaceid+"?client_id="+this.getSerial());
  4055.         }
  4056.     
  4057.     
  4058.     },
  4059.  
  4060.     scoreClicked: function (event) {
  4061.  
  4062.         //left mouse button clicked
  4063.         if (event.button == 0 ) {
  4064.  
  4065.                 if ( this.rotation ) {
  4066.                     this.toggleRotate();
  4067.                     return;
  4068.                 }
  4069.  
  4070.             //inc current game
  4071.             var nextmatch = this.getNextMatch();
  4072.  
  4073.             this.displayMatch ( nextmatch );
  4074.  
  4075.           //right mouse button
  4076.         } else if (event.button == 2) {
  4077.  
  4078.               this.buildMenu();
  4079.  
  4080.           }
  4081.  
  4082.     },
  4083.     
  4084.     
  4085.     
  4086.     bannerClicked: function (event,partnerid) {
  4087.         
  4088.         //left mouse button clicked
  4089.         if (event == null || event.button == 0) {
  4090.             
  4091.             this.openMatchReport("-1", 1, partnerid);    
  4092.  
  4093.         } 
  4094.  
  4095.     },
  4096.     
  4097.     icon1Clicked: function (event, partnerid) {
  4098.         
  4099.         //left mouse button clicked
  4100.         if (event == null || event.button == 0) {
  4101.             
  4102.             this.openMatchReport(this.selectedMatch.team1Id, 2,partnerid);    
  4103.  
  4104.         } 
  4105.  
  4106.     },
  4107.     
  4108.     
  4109.     icon2Clicked: function (event, partnerid) {
  4110.         
  4111.         //left mouse button clicked
  4112.         if (event == null || event.button == 0 ) {
  4113.             
  4114.             this.openMatchReport(this.selectedMatch.team2Id, 3, partnerid);    
  4115.  
  4116.         } 
  4117.  
  4118.     },
  4119.  
  4120.     
  4121.     contextMenuReportClicked1: function(partnerid) {
  4122.         
  4123.         this.openMatchReport(this.selectedMatch.team1Id, 4,partnerid);            
  4124.     
  4125.     },
  4126.     
  4127.     contextMenuReportClicked2: function(partnerid) {
  4128.         
  4129.         this.openMatchReport(this.selectedMatch.team1Id, 5,partnerid);            
  4130.     
  4131.     },
  4132.     
  4133.     openMatchReport: function(teamid, adspace,partnerid) {
  4134.     
  4135.         if (teamid==undefined)
  4136.             teamid="-1";
  4137.             
  4138.         var matchid = null;
  4139.         try {
  4140.             matchid = this.selectedMatch.matchID;
  4141.         } catch(e) {}
  4142.             
  4143.             
  4144.         var url = this.redirectURL+"redirect/"+partnerid+"/"+adspace+"/"+matchid+"/"+this.prefNode.getCharPref("locale")+"/"+teamid+"?client_id="+this.getSerial();
  4145.         
  4146.         this.visitWebpage(url);
  4147.         
  4148.     },
  4149.     
  4150.     openLeagueTable: function(matchid,adspace,partnerid) {
  4151.     
  4152.             
  4153.         var url = this.redirectURL+"redirect/"+partnerid+"/"+adspace+"/"+matchid+"/"+this.prefNode.getCharPref("locale")+"?client_id="+this.getSerial();
  4154.         
  4155.         this.visitWebpage(url);
  4156.         
  4157.     },
  4158.     
  4159.     openTeamNameLocalization: function() {
  4160.     
  4161.         var league = this.getLeagueByMatch ( this.selectedMatch );
  4162.         var leagueId = league.leagueID;
  4163.         
  4164.         this.visitWebpage("http://en.footiefox.com/database/translate_teams/"+leagueId);
  4165.     },
  4166.  
  4167.     openTeamInformation: function(icon, adspace) {
  4168.     
  4169.         var teamid = null;
  4170.         if (icon == "1")
  4171.             teamid = this.selectedMatch.team1Id;
  4172.         else
  4173.             teamid = this.selectedMatch.team2Id;
  4174.             
  4175.         this.visitWebpage(this.redirectURL+"redirect/"+this.prefNode.getCharPref("partner")+"/"+adspace+"/"+this.selectedMatch.matchID+"/"+this.prefNode.getCharPref("locale")+"/"+teamid+"?client_id="+this.getSerial());
  4176.     
  4177.     },
  4178.     
  4179.     cacheFile: function(src, overwrite, pListener) {
  4180.  
  4181.         if ( this.tmpDir == "" )
  4182.             return;
  4183.  
  4184.         var fileName = src.substring(src.lastIndexOf('/')+1, src.length);
  4185.         var fileSaving = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  4186.  
  4187.         try {
  4188.             fileSaving.initWithPath(this.tmpDir);
  4189.         } catch (e) {
  4190.             footiefox_d_error("Permission missing to access cache directory: "+e);
  4191.             return false;
  4192.         }
  4193.  
  4194.          // This is the directory we will be saving in - Create it in case it's a new folder and/or subfolder
  4195.         try {
  4196.             fileSaving.create(1, 0777);
  4197.         } catch (e) {}
  4198.  
  4199.  
  4200.         fileSaving.initWithPath(this.tmpDir + fileName);
  4201.         
  4202.         //download file if it does not exist yet, if overwriting is forced or if file size of the existing file is very small (the existing file is most probably broken)
  4203.         if (!fileSaving.exists() || overwrite || (fileSaving.exists() && fileSaving.fileSize < 500) ) {
  4204.  
  4205.  
  4206.             var cacheKey  = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
  4207.             cacheKey.data = src;
  4208.  
  4209.             var urifix  = Components.classes['@mozilla.org/docshell/urifixup;1'].getService(Components.interfaces.nsIURIFixup);
  4210.             var uri = urifix.createFixupURI(src, 0);
  4211.             var hosturi = null;
  4212.  
  4213.             if (uri.host.length > 0) {
  4214.                 hosturi = urifix.createFixupURI(uri.host, 0);
  4215.             }
  4216.  
  4217.             var persist = Components.classes['@mozilla.org/embedding/browser/nsWebBrowserPersist;1'].createInstance(Components.interfaces.nsIWebBrowserPersist);
  4218.             
  4219.             
  4220.             if (pListener != null)
  4221.                 persist.progressListener = pListener;
  4222.             
  4223.             persist.persistFlags = Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_BYPASS_CACHE | Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_CLEANUP_ON_FAILURE;
  4224.             persist.saveURI(uri, cacheKey, hosturi, null, null, fileSaving);
  4225.             
  4226.             
  4227.  
  4228.  
  4229.            }
  4230.        },
  4231.     
  4232.     manuallyUpdateTeamsList: function () {
  4233.         
  4234.     
  4235.         var ProgressListener = {
  4236.  
  4237.     
  4238.             onStateChange:function(aProgress,aRequest,aFlag,aStatus) {
  4239.                 
  4240.                 const STATE_STOP = Components.interfaces.nsIWebProgressListener.STATE_STOP; 
  4241.                 
  4242.                 if (aFlag & STATE_STOP) {
  4243.                     
  4244.                     //iFootieFox.login();
  4245.                     Components.classes["@mozilla.org/observer-service;1"]
  4246.                      .getService(Components.interfaces.nsIObserverService)
  4247.                      .notifyObservers(null, "footiefoxTeamsListUpdated", "");
  4248.                     
  4249.                 }
  4250.  
  4251.             },
  4252.                 
  4253.             onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {}
  4254.             
  4255.                 
  4256.         }
  4257.    
  4258.         this.cacheFile (this.apiURL + "teams.dat", true, ProgressListener);   
  4259.         
  4260.     
  4261.     },
  4262.     
  4263.  
  4264.        displayReconnect: function() {
  4265.  
  4266.         var labelnoconnection = document.getElementById("ff_notice_noconnection");
  4267.             try {
  4268.             labelnoconnection.setAttribute("label", this.dictionary.getString("ff.notice.reconnect"));
  4269.         } catch (e) {
  4270.                 labelnoconnection.setAttribute("label", "Reconnect");
  4271.  
  4272.         }
  4273.  
  4274.  
  4275.        },
  4276.  
  4277.         displayUnreconnect: function() {
  4278.  
  4279.         var labelnoconnection = document.getElementById("ff_notice_noconnection");
  4280.             try {
  4281.             labelnoconnection.setAttribute("label", this.dictionary.getString("ff.notice.noconnection"));
  4282.         } catch (e) {
  4283.                 labelnoconnection.setAttribute("label", "No connection");
  4284.         }
  4285.  
  4286.  
  4287.        },
  4288.     
  4289.     displaySelectLeagues: function() {
  4290.  
  4291.         var labelnoleagues = document.getElementById("ff_notice_noleagues");
  4292.             try {
  4293.             labelnoleagues.setAttribute("label", this.dictionary.getString("ff.notice.noleagueshover"));
  4294.         } catch (e) {
  4295.                 labelnoleagues.setAttribute("label", "Select leagues");
  4296.  
  4297.         }
  4298.  
  4299.  
  4300.        },
  4301.     
  4302.  
  4303.     displayUnselectLeagues: function() {
  4304.  
  4305.         var labelnoleagues = document.getElementById("ff_notice_noleagues");
  4306.             try {
  4307.             labelnoleagues.setAttribute("label", this.dictionary.getString("ff.notice.noleagues"));
  4308.         } catch (e) {
  4309.                 labelnoleagues.setAttribute("label", "No leagues selected");
  4310.  
  4311.         }
  4312.  
  4313.  
  4314.        },
  4315.  
  4316.  
  4317.        serializeData: function() {
  4318.                
  4319.         footiefox_d_message("serializeData");
  4320.  
  4321.         var serializedObject = new Object();
  4322.         
  4323.         try {
  4324.             serializedObject.myScoreboard = this.myScoreboard;
  4325.             
  4326.             serializedObject.messages = this.messages;
  4327.             serializedObject.lastMessage = this.lastMessage;
  4328.             serializedObject.teamslistlasttimestamp = this.teamslistlasttimestamp;
  4329.             serializedObject.leagueslistlasttimestamp = this.leagueslistlasttimestamp;
  4330.             serializedObject.updateInterval = this.updateInterval;
  4331.             serializedObject.myLeagues = this.myLeagues;
  4332.             serializedObject.myTeams = this.myTeams;
  4333.             serializedObject.activeLeagues = this.activeLeagues;
  4334.             serializedObject.leagueTimestamps = this.leagueTimestamps;
  4335.             serializedObject.banner = this.banner;
  4336.             serializedObject.iframes = this.iframes;
  4337.             serializedObject.scoreAds = this.scoreAds;
  4338.  
  4339.  
  4340.             var nowLocal = new Date();
  4341.             var currentTimestamp = nowLocal.getTime();
  4342.  
  4343.             serializedObject.timestamp = currentTimestamp;
  4344.         } catch (e) {
  4345.             footiefox_d_error("creation of serialization object failed: "+e);
  4346.         }
  4347.  
  4348.         
  4349.         var myJSONText = toJsonString(serializedObject);
  4350.         //var myJSONText = serializedObject.toJSONString();
  4351.         //var myJSONText = JSON.stringify(serializedObject);
  4352.         
  4353.         
  4354.  
  4355.         if ( this.tmpDir == "" )
  4356.             return false;
  4357.  
  4358.         var fileName = "scoreboard.json";
  4359.         var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  4360.  
  4361.  
  4362.         file.initWithPath(this.tmpDir + fileName);
  4363.         
  4364.  
  4365.         try {
  4366.             var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
  4367.                              .createInstance(Components.interfaces.nsIFileOutputStream);
  4368.  
  4369.             ////CRASHT HIER!!!!!!!
  4370.             // use 0x02 | 0x10 to open file for appending.
  4371.             foStream.init(file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate
  4372.             foStream.write(myJSONText, myJSONText.length);
  4373.             foStream.close();
  4374.         
  4375.         } catch (e) {
  4376.             
  4377.             this.prefNode.setCharPref("tempdir", "");
  4378.             footiefox_d_error("Failed to create temp folder!");
  4379.             
  4380.             
  4381.         }
  4382.  
  4383.         //notify non-first extensions to update their scoreboard
  4384.         Components.classes["@mozilla.org/observer-service;1"]
  4385.              .getService(Components.interfaces.nsIObserverService)
  4386.              .notifyObservers(null, "footiefoxRefreshData", "");
  4387.  
  4388.  
  4389.  
  4390.         return true;
  4391.        },
  4392.  
  4393.        parseSerializedData: function() {
  4394.     
  4395.         footiefox_d_message("parseSerializedData");
  4396.         
  4397.         this.whatsOnCalled = false;
  4398.  
  4399.         var data = "";
  4400.  
  4401.         try {
  4402.             var fileName = "scoreboard.json";
  4403.             var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  4404.  
  4405.  
  4406.             file.initWithPath(this.tmpDir + fileName);
  4407.  
  4408.  
  4409.  
  4410.             var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]
  4411.                                     .createInstance(Components.interfaces.nsIFileInputStream);
  4412.             var sstream = Components.classes["@mozilla.org/scriptableinputstream;1"]
  4413.                                     .createInstance(Components.interfaces.nsIScriptableInputStream);
  4414.             fstream.init(file, 1, 0, false);
  4415.             sstream.init(fstream);
  4416.  
  4417.             var str = sstream.read(4096);
  4418.             while (str.length > 0) {
  4419.                   data += str;
  4420.                   str = sstream.read(4096);
  4421.             }
  4422.  
  4423.             sstream.close();
  4424.             fstream.close();
  4425.  
  4426.           } catch (e) {
  4427.                 footiefox_d_error("failed to read serialized data file:"+e);
  4428.               return false;
  4429.           }
  4430.  
  4431.  
  4432.  
  4433.         try {
  4434.             //var serializedObject = eval('(' + data + ')');
  4435.             var serializedObject = data.parseJSON();
  4436.             //var serializedObject = JSON.parse(data);
  4437.             
  4438.             var timestamp = new Date(serializedObject.timestamp);
  4439.             
  4440.             var currentTimestamp = new Date();
  4441.  
  4442.             //serialized data outdated (past midnight GMT)
  4443.             if ( timestamp.getUTCDate() != currentTimestamp.getUTCDate() ) {
  4444.                 
  4445.                 if(serializedObject == false) {
  4446.                     footiefox_d_error("serialized data is corrupted!");
  4447.                 } else {
  4448.                     footiefox_d_error("serialized data outdated");
  4449.                 }
  4450.                 
  4451.                 
  4452.                 return false;
  4453.             }
  4454.  
  4455.  
  4456.             this.myScoreboard = serializedObject.myScoreboard;
  4457.  
  4458.             this.messages = serializedObject.messages;
  4459.             this.lastMessage = serializedObject.lastMessage;
  4460.             this.teamslistlasttimestamp = serializedObject.teamslistlasttimestamp;
  4461.             this.leagueslistlasttimestamp = serializedObject.leagueslistlasttimestamp;
  4462.             this.updateInterval = serializedObject.updateInterval;
  4463.             this.myLeagues = serializedObject.myLeagues;
  4464.             this.myTeams = serializedObject.myTeams;
  4465.             this.activeLeagues = serializedObject.activeLeagues;
  4466.             this.leagueTimestamps = serializedObject.leagueTimestamps;
  4467.             this.banner = serializedObject.banner;
  4468.             this.iframes = serializedObject.iframes;
  4469.             this.scoreAds = serializedObject.scoreAds;
  4470.  
  4471.  
  4472.             try {
  4473.                 this.processMessages();
  4474.                 this.processIFrames();
  4475.             } catch (e) {
  4476.  
  4477.                 footiefox_d_error("parseSerializedData: "+e);
  4478.  
  4479.             }
  4480.  
  4481.  
  4482.         } catch (e) {
  4483.             footiefox_d_error("failed to read serialized data " + e);
  4484.             return false;
  4485.         }
  4486.  
  4487.         this.fixUTF8Names();
  4488.  
  4489.         return true;
  4490.        },
  4491.  
  4492.     fixUTF8Names: function() {
  4493.  
  4494.         
  4495.         var countriesDataBundle = document.getElementById("countries-data-bundle");
  4496.         
  4497.         var teamsDataBundle = null;
  4498.         var teamsDataBundleUpdated = document.getElementById("teams-data-bundle-updated");
  4499.  
  4500.         //updated teams.dat valid
  4501.         if ( teamsDataBundleUpdated.hasAttribute("src") )
  4502.             teamsDataBundle = teamsDataBundleUpdated;
  4503.         //updated teams.dat corrupt, take inbuilt teams.dat
  4504.         else
  4505.             teamsDataBundle = document.getElementById("teams-data-bundle");
  4506.  
  4507.            //country names with special UTF8 codes are not properly written to the JSON file
  4508.            //here we assign them again from countries.dat
  4509.         for (var i=0; i<this.myScoreboard.length; i++) {
  4510.  
  4511.               var league = this.myScoreboard[i];
  4512.  
  4513.             var matches = league.matches;
  4514.  
  4515.             //localized country names
  4516.             for (var x=0; x<matches.length; x++) {
  4517.                     
  4518.                 var match = matches[x];
  4519.  
  4520.                 try {
  4521.                     
  4522.                     match.team1Title = countriesDataBundle.getString(match.team1Id);
  4523.                 
  4524.                 } catch (e) {
  4525.                         
  4526.                         try {
  4527.                             var value = teamsDataBundle.getString(match.team1Id);
  4528.                             match.team1Title = value.split(":")[1];
  4529.                             
  4530.                         } catch (e) {
  4531.                             match.team1Title = "<" + iFootieFox.dictionary.getString("ff.notice.notitle") + ">";
  4532.  
  4533.                     }
  4534.                 }
  4535.                 
  4536.                 try {
  4537.                             
  4538.                     match.team2Title = countriesDataBundle.getString(match.team2Id);
  4539.                 
  4540.                 } catch (e) {
  4541.                         
  4542.                         try {
  4543.                             var value = teamsDataBundle.getString(match.team2Id);
  4544.                             match.team2Title = value.split(":")[1];
  4545.                             
  4546.                         } catch (e) {
  4547.                             match.team2Title = "<" + iFootieFox.dictionary.getString("ff.notice.notitle") + ">";
  4548.  
  4549.                     }
  4550.                 }
  4551.                 
  4552.                 league.matches[x] = match;
  4553.                 
  4554.                 
  4555.             }
  4556.  
  4557.             this.myScoreboard[i] = league;
  4558.  
  4559.         }
  4560.  
  4561.         
  4562.  
  4563.     },
  4564.     
  4565.   
  4566.     statusbarArrowClicked: function(event) {
  4567.     
  4568.         
  4569.         
  4570.         if ( event.button == 0 ) {
  4571.             
  4572.             
  4573.             this.buildMenu();
  4574.             var contextmenu = document.getElementById('menupopup_mainmenupopup');
  4575.             var deck_footiefox_arrow = document.getElementById('deck_footiefox_arrow');
  4576.             contextmenu.showPopup(deck_footiefox_arrow,-1,-1,'context','topleft','bottomleft');
  4577.                 
  4578.             
  4579.             
  4580.         }
  4581.         
  4582.     },
  4583.     
  4584.     
  4585.     
  4586.     statusbarArrowHover: function() {
  4587.    
  4588.         var arrow = document.getElementById('ff_contextmenu_arrow');
  4589.         arrow.setAttribute("style","list-style-image: url('chrome://global/skin/arrow/arrow-up.gif');margin-right:0px;margin-left:0px;margin-top:8px;margin-bottom:10px;min-height:3px;max-height:3px;max-width:5px;");
  4590.     
  4591.     
  4592.     },
  4593.     
  4594.     statusbarArrowOut: function() {
  4595.     
  4596.         var arrow = document.getElementById('ff_contextmenu_arrow');
  4597.         arrow.setAttribute("style","list-style-image: url('chrome://footiefox/skin/arrow-up-green.gif');margin-right:0px;margin-left:0px;margin-top:8px;margin-bottom:10px;min-height:3px;max-height:3px;max-width:5px;");
  4598.     
  4599.     
  4600.     },
  4601.     
  4602.     getLocalPartner: function(loc) {
  4603.     
  4604.         var partnersEnum = this.partners.strings;
  4605.         var index = -1;
  4606.         while (partnersEnum.hasMoreElements()) {
  4607.         
  4608.                 try {
  4609.  
  4610.                 var element = partnersEnum.getNext();
  4611.  
  4612.                 var key = element.QueryInterface(Components.interfaces.nsIPropertyElement).key;
  4613.                 var value = element.QueryInterface(Components.interfaces.nsIPropertyElement).value;
  4614.                     
  4615.                 if (value.split(":")[0]==loc) {
  4616.                     index = key;
  4617.                     break;
  4618.                 }
  4619.  
  4620.             } catch(ex){
  4621.                         footiefox_d_error(ex); continue;
  4622.             }
  4623.         }
  4624.         
  4625.         return index;
  4626.     },
  4627.     
  4628.     applyPartnerOverlay: function() {
  4629.         
  4630.         var partner = null;
  4631.         var partnerNum = this.prefNode.getCharPref("partner");
  4632.         var menupopup_icon1_propose = document.getElementById("menupopup_icon1_propose");
  4633.         var menupopup_icon2_propose = document.getElementById("menupopup_icon2_propose");
  4634.         var menupopup_icon1_sep = document.getElementById("menupopup_icon1_sep");
  4635.         var menupopup_icon2_sep = document.getElementById("menupopup_icon2_sep");
  4636.         
  4637.         try {
  4638.           
  4639.             // find locale partner
  4640.             partner = this.partners.getString(this.getLocalPartner(this.prefNode.getCharPref("locale"))).split(":")[1];
  4641.             menupopup_icon1_propose.setAttribute("collapsed","true");
  4642.             menupopup_icon2_propose.setAttribute("collapsed","true");
  4643.             menupopup_icon1_sep.setAttribute("hidden","true");
  4644.             menupopup_icon2_sep.setAttribute("hidden","true");
  4645.             
  4646.             
  4647.              
  4648.         } catch (e) {
  4649.         
  4650.             
  4651.             // no locale partner
  4652.           
  4653.             partner = this.partners.getString(partnerNum).split(":")[1];
  4654.             
  4655.             menupopup_icon1_propose.setAttribute("label", "Propose local partner for '" + this.prefNode.getCharPref("locale") +"'");
  4656.             menupopup_icon2_propose.setAttribute("label", "Propose local partner for '" + this.prefNode.getCharPref("locale") +"'");
  4657.             menupopup_icon1_propose.setAttribute("collapsed","false");
  4658.             menupopup_icon2_propose.setAttribute("collapsed","false");
  4659.             menupopup_icon1_sep.setAttribute("hidden","false");
  4660.             menupopup_icon2_sep.setAttribute("hidden","false");
  4661.             
  4662.          
  4663.         }
  4664.  
  4665.         
  4666.         this.addToolbarButtons();
  4667.         
  4668.             
  4669.         var statusbar = document.getElementById("statusbarpanel_partner_logo");
  4670.         statusbar.setAttribute("src", "chrome://footiefox/skin/"+partnerNum+"/statusbar.png");
  4671.         
  4672.         //deck partner logo
  4673.         var label = document.getElementById("deck_partner_logo");
  4674.         
  4675.         
  4676.         if (!this.prefNode.getBoolPref("partner.statusbarlabel")) {
  4677.             
  4678.             label.setAttribute("hidden", "true");
  4679.             label.setAttribute("collapsed", "true");
  4680.         } else {
  4681.             
  4682.         
  4683.             label.setAttribute("hidden", "false");
  4684.             label.setAttribute("collapsed", "false");
  4685.         
  4686.         }
  4687.         
  4688.         //goal alert partner banner
  4689.         var alert_partner = document.getElementById("ff_alert_partner");
  4690.         alert_partner.setAttribute("src", "chrome://footiefox/skin/"+partnerNum+"/goalalert.png");
  4691.         
  4692.  
  4693.     
  4694.     
  4695.     },
  4696.     
  4697.     
  4698.     //DEMO
  4699.     triggerGoalManually: function(team) {
  4700.                 footiefox_d_message("triggerGoalManually");
  4701.  
  4702.         try{
  4703.             var matchDiffs = new Array();
  4704.             
  4705.             var cmatch = iFootieFox.selectedMatch;
  4706.  
  4707.             var matchDiff = new Object();
  4708.             matchDiff.matchId = cmatch.matchID;
  4709.     
  4710.             var match = iFootieFox.getMatch( matchDiff.matchId );
  4711.             matchDiff.team1Score = parseInt(cmatch.team1Score);
  4712.             matchDiff.team2Score = parseInt(cmatch.team2Score);
  4713.             matchDiff.phase = cmatch.phase;
  4714.             
  4715.             if (team == 0) {
  4716.                 matchDiff.team1Score +=1;
  4717.                 matchDiff.teamId = match.team1Id;
  4718.             } else {
  4719.                     matchDiff.team2Score +=1;
  4720.                     matchDiff.teamId = match.team2Id;
  4721.                     
  4722.             }
  4723.  
  4724.     
  4725.  
  4726.             matchDiff.status = cmatch.status;
  4727.     
  4728.             matchDiffs.push(matchDiff);
  4729.         
  4730.  
  4731.             this.updateData(matchDiffs,0);
  4732.         } catch (e) {
  4733.             footiefox_d_error(e);
  4734.  
  4735.         }
  4736.  
  4737.  
  4738.     }
  4739.  
  4740. };
  4741.  
  4742.  
  4743.  
  4744. function playAlarmSound(sURL_str) {
  4745.  
  4746.     var sample = iFootieFox.soundPlayer.QueryInterface(Components.interfaces.nsISound);
  4747.       var ioService = Components.classes["@mozilla.org/network/io-service;1"]
  4748.             .getService(Components.interfaces.nsIIOService);
  4749.     var url = ioService.newURI(sURL_str, null, null);
  4750.       sample.play(url);
  4751.  
  4752. }
  4753.  
  4754.  
  4755.  
  4756. // Dump a message to Javascript Console
  4757. function footiefox_d_message(msg){
  4758.     
  4759.     if (footiefox_d == 1) {
  4760.         var acs = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
  4761.         acs.logStringMessage("FootieFox: " + msg);
  4762.     }
  4763. }
  4764.  
  4765. function footiefox_d_error(msg){
  4766.  
  4767.     var acs = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
  4768.     acs.logStringMessage("FootieFox: " + msg);
  4769. }
  4770.  
  4771.  
  4772. function footiefox_di_message(msg) {
  4773.  
  4774.     if (footiefox_d == 1) {
  4775.         var jetzt = new Date();
  4776.         footiefox_d_error(msg + ": " + jetzt);
  4777.     }
  4778. }
  4779.  
  4780. function dscore() {
  4781.     
  4782.     //debug scoreboard list
  4783.     for (var x=0; x<iFootieFox.myScoreboard.length; x++) {
  4784.                 var league = iFootieFox.myScoreboard[x];
  4785.                 var matches = league.matches;
  4786.  
  4787.                 for (var y=0; y<matches.length; y++) {
  4788.                     var match = matches[y];
  4789.                         var dat = new Date();
  4790.                         dat.setTime(match.startTime),
  4791.             footiefox_d_message( dat + " " + match.team1Title + match.team2Title);
  4792.                 }
  4793.         }
  4794. }
  4795.  
  4796.  
  4797. function myObservers() {
  4798.  
  4799.     this.register();
  4800. }
  4801.  
  4802. myObservers.prototype = {
  4803.     observe: function(subject, topic, data) {
  4804.  
  4805.     if (topic == "alertclickcallback")
  4806.             window.setTimeout("iFootieFox.openMessageURL()", 0);
  4807.  
  4808.     if (topic == "footiefoxRefreshData") {
  4809.             //iFootieFox.removeMenu();
  4810.         if (!iFootieFox.firstExtension)
  4811.             if ( iFootieFox.parseSerializedData() )
  4812.                 iFootieFox.dataRefreshed();
  4813.     }
  4814.  
  4815.  
  4816.     if (topic == "footiefoxTriggerUpdate") {
  4817.         //iFootieFox.browserStartUp = false;
  4818.         iFootieFox.optionsClosed = true;
  4819.         setTimeout("iFootieFox.callWhatsOn(true)", 50);
  4820.     }
  4821.             
  4822.  
  4823.     if (topic == "footiefoxManuallyUpdateTeamsList") {
  4824.         
  4825.         setTimeout("iFootieFox.manuallyUpdateTeamsList()", 0);
  4826.         
  4827.     }
  4828.         
  4829.  
  4830.     if (topic == "footiefoxUpdateRotation")
  4831.         if (iFootieFox.rotation)
  4832.                 window.setTimeout("iFootieFox.updateRotationTimer()", 0);
  4833.  
  4834.     if (topic == "footiefoxMaximized")
  4835.         iFootieFox.checkWindowMaximized();
  4836.  
  4837.     if (topic == "footiefoxGoalAlert") {
  4838.  
  4839.         iFootieFox.updateAlertSlider(data);
  4840.         iFootieFox.showSlider();
  4841.     }
  4842.  
  4843.  
  4844.     if (topic == "footiefoxOptionsClosed") {
  4845.  
  4846.         iFootieFox.displayMatch(iFootieFox.selectedMatch);
  4847.         iFootieFox.applyPartnerOverlay();
  4848.         //iFootieFox.dataRefreshed();
  4849.         window.setTimeout("iFootieFox.dataRefreshed()",0);
  4850.     }
  4851.     
  4852.     if (topic == "footiefoxWizardFinished") {
  4853.         
  4854.         
  4855.         iFootieFox.applyPartnerOverlay();
  4856.         
  4857.         if (data=="true")
  4858.             iFootieFox.openOptions('ff_options_tabs_leagues');
  4859.             
  4860.         if (!iFootieFox.isSearchEngineInstalled())
  4861.                     iFootieFox.addSearchEngine();
  4862.                 
  4863.  
  4864.  
  4865.     }
  4866.  
  4867.  
  4868.  
  4869.     },
  4870.     register: function() {
  4871.  
  4872.         iFootieFox.checkFirstExtension();
  4873.  
  4874.         var observerService = Components.classes["@mozilla.org/observer-service;1"]
  4875.                           .getService(Components.interfaces.nsIObserverService);
  4876.  
  4877.         observerService.addObserver(this, "footiefoxTriggerUpdate", false);
  4878.         observerService.addObserver(this, "footiefoxUpdateRotation", false);
  4879.         observerService.addObserver(this, "footiefoxRefreshData", false);
  4880.         observerService.addObserver(this, "footiefoxMaximized", false);
  4881.         observerService.addObserver(this, "footiefoxGoalAlert", false);
  4882.         observerService.addObserver(this, "footiefoxOptionsClosed", false);
  4883.         observerService.addObserver(this, "footiefoxManuallyUpdateTeamsList", false);
  4884.         observerService.addObserver(this, "footiefoxWizardFinished", false);
  4885.  
  4886.  
  4887.     },
  4888.     unregister: function() {
  4889.             var observerService = Components.classes["@mozilla.org/observer-service;1"]
  4890.                           .getService(Components.interfaces.nsIObserverService);
  4891.  
  4892.         if (iFootieFox.firstExtension) {
  4893.                   observerService.removeObserver(iFootieFox, "footiefoxExtension");
  4894.           }
  4895.  
  4896.         observerService.removeObserver(this, "footiefoxTriggerUpdate");
  4897.         observerService.removeObserver(this, "footiefoxUpdateRotation");
  4898.         observerService.removeObserver(this, "footiefoxRefreshData");
  4899.         observerService.removeObserver(this, "footiefoxMaximized");
  4900.         observerService.removeObserver(this, "footiefoxGoalAlert");
  4901.         observerService.removeObserver(this, "footiefoxOptionsClosed");
  4902.         observerService.removeObserver(this, "footiefoxManuallyUpdateTeamsList");
  4903.         observerService.removeObserver(this, "footiefoxWizardFinished");
  4904.  
  4905.  
  4906.     }
  4907. }
  4908.  
  4909. function inArray(element, list) {
  4910.  
  4911.     for (var i=0; i<list.length; i++) {
  4912.         if (list[i] == element)
  4913.             return true;
  4914.     }
  4915.  
  4916.     return false;
  4917.  
  4918.  
  4919. }
  4920.  
  4921. function whereIsFootieFox() {
  4922.  
  4923.     var eleBrowser = getBrowser();
  4924.     eleBrowser.contentWindow.packageExists = 12;
  4925.  
  4926.     
  4927.  
  4928.  
  4929. }